Link to home
Start Free TrialLog in
Avatar of bimalprakashsharma
bimalprakashsharma

asked on

DOS run a program as another user

DOS RUNAS feature
I have a .bat file which runs as a user logs in. I want to run a program as another user so I am using the run as feature to do this. RUNAS requires me to enter a password manually. How can I put in the password without any user intervention
Avatar of sirbounty
sirbounty
Flag of United States of America image

Hello bimalprakashsharma,
Not only will you not be able to with runas, you shouldn't.  It would expose your password if you tried this....

~sirbounty
What is it you're looking to accomplish - perhaps there's another way...

For example, use schtasks to run local tasks using the System account.

schtasks /create /ru system /sc once /st 09:00:00 /tn TaskName /tr "c:\program.bat"

Avatar of bimalprakashsharma
bimalprakashsharma

ASKER

sirbounty:

My users do not have access to a folder in c drive. I want to automatically copy a file in one of the folders which the normal user does not have access to. How can I do this?
Have a list of computers?
Something like this could work:

for /f %%a in (C:\Computers.txt) do copy c:\sourcefile.txt \\%%a\c$\protectedfolder
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

I am now running the update as an active directory script. Some computers update while others don't. Why is this?
Try adding some logging.... run something like this as part of the batch file

@echo off
echo %date% %time% START >> \\server\share\logfile-%computername%.txt
\\\server\share\yourprogram.exe >>\\server\share\logfile-%computername%.txt
echo %date% %time% STOPPED >> \\server\share\logfile-%computername%.txt

then look at logfile-computersname.txt for what went on.

Steve

I have done the log file method you have suggested and it says "(0) files copied" on the computer that does not work. Why does it work on some and not on others?
Try adding 2>>\\server\share\logfile-%computername%.txt to the line aswell.  That will capture any error messages too.

Steve