Thursday, 15 October 2015

Windows Command Line

Runas is a very useful command on Windows OS. This command enables one to run a command in the context of another user account.

Run a program from another user account

The command to launch a program using another user credentials is given below.

runas /user:domainname\username program

For example, if you want to open registry editor as administrator of the computer, the command would be as below.

runas /user:administrator regedit

After running the above command, you will be asked to enter the password of administrator account. After password validation, registry editor will be opened with the administrator account credentials.

To specify arguments to the program

If you need to provide arguments to the program that need to be invoked as another user, you can put the program name and the parameters in double quotes.

runas /user:username "program argument1 argument2 ..."
For example to open the file C:\boot.ini as administrator, the command would be:

runas /user:administrator "notepad C:\boot.ini"

Running command prompt as another user 

If you have multiple commands need to be executed with administrator(or any other user )credentials, instead of running each command using runas, you can open command prompt window once as the administrator and then run all the commands in that window. Below is the command for opening a command window using runas.

runas /user:administrator cmd

Example:

C:\>runas /user:administrator cmd
Enter the password for administrator:
Attempting to start cmd as user "techblogger-pc\administrator" ...
It will launch new command window after printing the above message.

Run a batch file as administrator

To run a batch file as administrator of the computer, you need to mention the path of the batch file in the place of command in the runas syntax.

For example, to run the batch file located at c:\data\mybatchfile.bat, you need to run the below command.

runas /user:administrator C:\data\mybatchfile.bat

Export Folder list


Click Start, click All Programs, click Accessories, right-click Command Prompt, and select Run as Administrator.
 
b. Browse to the location that contains the files and folders whose list of names you want to generate.
 
cd <path>

Export folder name
Dir /b > Myfileslist.txt

Export folder name with sub folder
Dir /s /b /o:n /ad > Myfileslist.txt