How to run a executable by passing the Run As user as its commandline parameter?

  • Thread starter Thread starter Tony
  • Start date Start date
T

Tony

Hi,
I'm in urgent need of help. We know that if we want to
run a executable as a differet user, we shift-right click
and then say 'run as' and specific different parameters.
I need to automate this. So, How do I execute an
executable by passing the 'Run as User' username and
password, domain etc, as commandline ? How do I do that
in VB, or VB Script or Windows Script or by using any
other commandline tool to invoke the executable with a
different username and password. The reason why we need
this is, we need to provide access for users to run an
executable, but when they invoke it we don't want it to be
run using their logon id. Instead we wanted to give it
permanantly a different logon userid with higher
privileges which is actually transparent to the user. But
we don't want the user to know the password of that id.

For e.g if the executable to be run is XX.EXE I want to
do something like one of the following:
a)
XX.EXE /RUSER myusername, /Rpass mypass /RDomain mydomain

(or)

b)MYVBprogram.exe /executable XX.EXE /RUSER
myusername, /Rpass mypass /RDomain mydomain

Thanks much
 
Tony said:
I'm in urgent need of help. We know that if we want to
run a executable as a differet user, we shift-right click
and then say 'run as' and specific different parameters.
I need to automate this. So, How do I execute an
executable by passing the 'Run as User' username and
password, domain etc, as commandline ?

I should tell you that I know nothing of VB and very little about scripting.
What I do know well is Windows 2000 and Windows XP define the "API function"
CreateProcessWithLogonW() so that a caller can create a process that runs an
executable and specify the credentials (domain, username and password) under
which it runs.

If you can find someone to translate the C++ hack below to VB you should be
good to go. Note that this

TEXT("depalo"), TEXT("."), TEXT("william"),

is used to log the user 'depalo' into the local machine using the password
'william'. If you need to specify a domain change the '.' to whatever is
appropriate.

Note too that this line

TEXT("notepad C:\\this is a test file.txt");

specifies the parameters of the command passed to the executable. Many
programs (including notepad) expect their names to be repeated as the first
parameter.

Finally note that you'd have to change this

TEXT("notepad.exe"),

to the (possibly fully qualified) name of the executable that you wish to
run.

Regards,
Will

#define UNICODE
#define _UNICODE
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <iostream>

int main()
{
int nErr;
BOOL bOK;
TCHAR szFileName[] = TEXT("notepad C:\\this is a test
file.txt");
STARTUPINFO si;
PROCESS_INFORMATION pi;

memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWNORMAL;

bOK = CreateProcessWithLogonW(TEXT("depalo"), TEXT("."), TEXT("william"),
LOGON_WITH_PROFILE,
TEXT("notepad.exe"), szFileName, 0, NULL,
TEXT("C:\\"), &si, &pi);

if ( bOK )
nErr = 0;

else
nErr = GetLastError();

std::cout << "Process creation completes with a status of " << nErr <<
std::endl;

CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);

return 0;
}
 
Back
Top