RE: Windows Server 2003 - Running a service as a Local System account.
From: Mike (Mike_at_discussions.microsoft.com)
Date: 09/10/04
- Next message: Mike: "GetSystemMetrics(SM_REMOTESESSION) and services"
- Previous message: KeithHa [MSFT]: "Re: about redirect to read from and write to a specific file"
- In reply to: Mike M.: "Windows Server 2003 - Running a service as a Local System account."
- Next in thread: Mike M.: "Re: Windows Server 2003 - Running a service as a Local System account."
- Reply: Mike M.: "Re: Windows Server 2003 - Running a service as a Local System account."
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 10 Sep 2004 10:07:09 -0700
If you have the username and password, just call LogonUser() and
ImpersonateLoggedOnUser(). Then access your files. This will access the
files as the user that you logged on. Then you can call RevertToSelf() to
set the thread context back to the local system when you are done. Make sure
that you clean up these handles.
-Mike
"Mike M." wrote:
> I have a service that was written in VC 6.0 under Windows Server 2003. It
> has a GUI and an icon that I place in the task tray. Double clicking the
> icon displays the GUI. The service is set to start automatically and run
> 24x7. I had to add a feature to the service to periodically copy files from
> another machine for failover purposes. Unfortunately it cannot access the
> other machine while running as a Local System account and will not "allow
> interact with desktop" if running as a specific user account. I know a
> service with a GUI is not ideal but before I spend the time (which I don't
> have) to decouple those parts, is there a method I could run a batch file or
> process as a specified User and achieve my goals?
>
> I have tried the following but can't get the CreateProcessWithLogonW to
> succeed with correct values:
> // load the administrator profile
> DWORD dwLogonFlags = LOGON_WITH_PROFILE;
>
> PROCESS_INFORMATION ProcessInfo;
> STARTUPINFOW StartupInfo = {0};
> StartupInfo.cb = sizeof(STARTUPINFOW);
> StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
> StartupInfo.wShowWindow = SW_SHOWNORMAL;
>
> // go do it!
> if (!CreateProcessWithLogonW((LPCWSTR)wszAdminName,
> (LPCWSTR)wszDomain, (LPCWSTR)wszPassword, dwLogonFlags,
> (LPCWSTR)wszApplicationName, (LPWSTR)wszCommandline, 0, NULL, NULL,
> &StartupInfo, &ProcessInfo))
>
>
> TIA.
>
>
>
- Next message: Mike: "GetSystemMetrics(SM_REMOTESESSION) and services"
- Previous message: KeithHa [MSFT]: "Re: about redirect to read from and write to a specific file"
- In reply to: Mike M.: "Windows Server 2003 - Running a service as a Local System account."
- Next in thread: Mike M.: "Re: Windows Server 2003 - Running a service as a Local System account."
- Reply: Mike M.: "Re: Windows Server 2003 - Running a service as a Local System account."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|