From inside my batch file I need to run an application as a different user,
similar to the Run As command from the desktop. I'm currently using a DOS
Batch file but could use a vbscript batch as well.

Is there a way to exexcute a file from a batch file as a different user?

My current solution is using a Scheduled Task that is configured to run as a
different user and then I run that Task from the batch file.
schtasks /run /tn wbp04324_filecopy

I'd like to avoid using the Scheduled Task if I can call it directly.

Thanks, -phil


--
no place like 127.0.0.1

RE: Run As command from inside batch file by v-wywang

v-wywang
Fri Mar 30 08:51:07 CDT 2007

Hi Phil,

I think RunAs.exe is what you need. The following VBScript works fine on
Win2000. However, it will not work on Win2003. In Win2003 scenario, I'm
afraid we have to consider using Scheduled Task.

sUser="Domain\Username"
sPass="Password"&"{enter}"
strCmd ="notepad.exe"
set WshShell = CreateObject("WScript.Shell")
rc=WshShell.Run("runas /user:" & sUser & " " & CHR(34) & strCmd & CHR(34)
,1,False)
Wscript.Sleep 1000 'need to give time for window to open.
WshShell.AppActivate("runas.exe") 'make sure we grab the right window to
send password to
WshShell.SendKeys sPass 'send the password to the waiting window.
set WshShell=Nothing
wscript.quit

Hope this helps. If you have any further issue, please feel free to let me
know. I'm glad to assist you.

Have a great day,
Wen Yuan
Microsoft Online Community Support
===============================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
===============================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Re: Run As command from inside batch file by Stace

Stace
Fri Mar 30 17:54:53 CDT 2007


"vbphil" <vbphil@online.nospam> wrote in message
news:181D6B5A-376E-441E-8BBE-3A66EEE4540C@microsoft.com...
> From inside my batch file I need to run an application as a different
> user,
> similar to the Run As command from the desktop. I'm currently using a DOS
> Batch file but could use a vbscript batch as well.
>
> Is there a way to exexcute a file from a batch file as a different user?
>
> My current solution is using a Scheduled Task that is configured to run as
> a
> different user and then I run that Task from the batch file.
> schtasks /run /tn wbp04324_filecopy
>
> I'd like to avoid using the Scheduled Task if I can call it directly.
>
> Thanks, -phil
>

Take a look as CPAU:
http://www.joeware.net/freetools/tools/cpau/index.htm

Should do what you want and can encode the job file so that prying eyes
cannot determine the credentials used to run it.

HTH
Stace.
>
> --
> no place like 127.0.0.1



Re: Run As command from inside batch file by vbphil

vbphil
Sat Mar 31 09:10:03 CDT 2007

Thanks for your suggestions.

I tried CPAU but I guess my situation is more complex than I eluded and I
couldn't get it to work. The rest of the details are. My script that will
envoke running an application as another user will be executed by the local
SYSTEM account. The user I need to impersonate is a Windows AD domain user
account and this is all running in 32Bit mode on a Win64 3K server.

So, for now, I guess using the Windows Task Scheduler is the way to go. My
script, running as the local SYSTEM account, can configure the Task Scheduler
to run another application as a domain AD user. I can supply the password in
the Task setup as well. This is presently working.

I was hoping RunAs.exe might do it but it doesn't accept a password
parameter. Oh Well.


"Stace" wrote:

>
> "vbphil" <vbphil@online.nospam> wrote in message
> news:181D6B5A-376E-441E-8BBE-3A66EEE4540C@microsoft.com...
> > From inside my batch file I need to run an application as a different
> > user,
> > similar to the Run As command from the desktop. I'm currently using a DOS
> > Batch file but could use a vbscript batch as well.
> >
> > Is there a way to exexcute a file from a batch file as a different user?
> >
> > My current solution is using a Scheduled Task that is configured to run as
> > a
> > different user and then I run that Task from the batch file.
> > schtasks /run /tn wbp04324_filecopy
> >
> > I'd like to avoid using the Scheduled Task if I can call it directly.
> >
> > Thanks, -phil
> >
>
> Take a look as CPAU:
> http://www.joeware.net/freetools/tools/cpau/index.htm
>
> Should do what you want and can encode the job file so that prying eyes
> cannot determine the credentials used to run it.
>
> HTH
> Stace.
> >
> > --
> > no place like 127.0.0.1
>
>
>