#73764 - 2003-02-28 11:50 AM
Re: RUNAS
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
k, richard could package this in kixcrypt:
code:
// RunAS.cpp : Defines the entry point for the console application.
// Logon and run an app as a different user // 1 2 3 4 5 6 // params: user, password, domain, appname, folder, commandline // Batch file example: // RunAs Administrator, 123456,,D:\Installer.exe, d:\, -i
#include "stdafx.h"
// params user, password, domain, appname, folder, commandline
int main(int argc, char* argv[]) { int LOGON_WITH_PROFILE = 1; int LOGON_NETCREDENTIALS_ONLY = 2; int res; // results int creationflags; // flags to pass to define window type int myerrorlevel; // errorlevel for this function static PROCESS_INFORMATION myprocessinfo; // process return static STARTUPINFO mystartupinfo; // set window flags creationflags=CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP; // initailise the startupinfo structure ::ZeroMemory(&mystartupinfo, sizeof(mystartupinfo));
// load in size of structure mystartupinfo.cb = sizeof(mystartupinfo);
// CreateProcessWithLogonW parameters: // LPCWSTR lpUsername, // LPCWSTR lpDomain, // LPCWSTR lpPassword, // DWORD dwLogonFlags, // LPCWSTR lpApplicationName, // LPWSTR lpCommandLine, // DWORD dwCreationFlags, // LPVOID lpEnvironment, // LPCWSTR lpCurrentDirectory, // LPSTARTUPINFOW lpStartupInfo, // LPPROCESS_INFORMATION lpProcessInfo // todo // concatenate commandline arguments into a string // argv[6 and +] should be moved into a string
// Start the process res=CreateProcessWithLogonW(argv[1], argv[3], argv[2], LOGON_WITH_PROFILE, argv[4], argv[6], creationflags, NULL, argv[5], &mystartupinfo, &myprocessinfo);
// return errorlevel myerrorlevel=0; if (res==0){ myerrorlevel=1; } else { // close unwanted handles CloseHandle (myprocessinfo.hThread); // close the handle to the main thread, since we don't use it CloseHandle (myprocessinfo.hProcess); // close handle to the process } return (myerrorlevel); }
_________________________
!download KiXnet
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 320 anonymous users online.
|
|
|