Wednesday, 19 August 2015

Using The Absolute Path

Today i'm Going to Write something about using Absolute Path.

Lets Start with a try, open windows PowerShell and type dir 

PS C:\users\kvprasoon> dir


    Directory: C:\users\kvprasoon


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        8/19/2015   2:06 PM                Contacts
d-----        8/19/2015   2:06 PM                Desktop
d-----        8/19/2015   2:06 PM                Documents
d-----        8/19/2015   2:06 PM                Downloads
d-----        8/19/2015   2:06 PM                Favorites
d-----        8/19/2015   2:06 PM                Links
d-----        8/19/2015   2:06 PM                mcafee dlp quarantined files
d-----        8/19/2015   2:06 PM                Music
d-----        8/19/2015   2:06 PM                Pictures
d-----        8/19/2015   2:06 PM                Saved Games
d-----        8/19/2015   2:06 PM                Searches
d-----        8/19/2015   2:06 PM                Videos
-a----        3/12/2015  12:43 PM              0 msinfo.txt

dir will list contents in The current directory.

Here you can see a text file name msinfo.txt, Lets try to open it.
Normally , we use to do PS C:\users\kvprasoon> msinfo.txt



Here its Throws an error Saying
msinfo.txt : The term 'msinfo.txt' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
At line:1 char:1
+ msinfo.txt
+ ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (msinfo.txt:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Yes, There is no cmdlet,Function,Script or any other operable program named msinfo.txt.
PowerShell need Absolute path to open a file and is a wonderful feature in PowerShell when we think about security.
So what is Absolute Path ?
 Absolute path is a path for a file using its complete full path name.

and you can see, Powershell is well enough to understand what we were trying to do and is show by providing suggestion. And here also we've got one.You can see it next line of the thrown error.

Suggestion [3,General]: The command msinfo.txt was not found, but does exist in the current location. Windows PowerShell does not load commands from the current loca
tion by default. If you trust this command, instead type: ".\msinfo.txt". See "get-help about_Command_Precedence" for more details.

So PowerShell is suggesting us by saying that msinfo.txt is there in the location, But Windows PowerShell Does not loads commands from current location by default.The way to accomplish this is by using .'\'  or by typing the fullpath 'c:\Users\Kvprasoon\msinfo.txt' .

Here it is,


This is one of the way how Windows PowerShell gives us security in running executables and other scripts from the current location.








No comments:

Post a comment