Hi all,
I've been playing with the WinLogon Notification Package, which amounts to writing a DLL and adding some registry entries to the [tt]HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Notify[/tt] key, ie.
This tells Windows that when logging off, to run the [tt]RunBackup[/tt] procedure in the BackupSys.dll library I wrote. This all works, which should be cause for joy, except that the backup procedure I want to run is via a batch file (the batch file does get launched) and I'm getting access denied messages when attempting to access a network share.
This could be for two reasons that I can think of:
[ol][li]The network connections have already been closed by the time my batch file is running[/li]
[li]The batch file is being run not as the logged on user, and so doesn't have permission to access the network share[/li][/ol]
This is the relevant bit of my library code:
I added the [tt]ImpersonateLoggedOnUser[/tt] line after seeing it on another forum, but it hasn't helped. Just to reiterate, the batch file is getting called, but failing when trying to access the network share.
Can anyone give me some help in getting this working?
Thanks.
I've been playing with the WinLogon Notification Package, which amounts to writing a DLL and adding some registry entries to the [tt]HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Notify[/tt] key, ie.
Code:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Notify\Backup]
"Asynchronous"=dword:00000000
"Impersonate"=dword:00000001
"DllName"="BackupSys.dll"
"Logoff"="RunBackup"
This tells Windows that when logging off, to run the [tt]RunBackup[/tt] procedure in the BackupSys.dll library I wrote. This all works, which should be cause for joy, except that the backup procedure I want to run is via a batch file (the batch file does get launched) and I'm getting access denied messages when attempting to access a network share.
This could be for two reasons that I can think of:
[ol][li]The network connections have already been closed by the time my batch file is running[/li]
[li]The batch file is being run not as the logged on user, and so doesn't have permission to access the network share[/li][/ol]
This is the relevant bit of my library code:
Code:
[b]type[/b]
[blue]// this structure required in procedure header[/blue]
PWLX_NOTIFICATION_INFO = ^TWLX_NOTIFICATION_INFO;
TWLX_NOTIFICATION_INFO = [b]record[/b]
Size: ULong;
Flags: ULong;
Username: PWideChar;
WindowStation: PWideChar;
hToken: THandle;
hDesktop: HDesk;
pStatusCallback: LongInt;
[b]end[/b];
[b]procedure[/b] RunBackup(pInfo: PWLX_NOTIFICATION_INFO); [b]safecall[/b];
[b]var[/b]
r : Integer;
[b]begin[/b]
ImpersonateLoggedOnUser(pInfo^.hToken);
WinExecAndWait32('c:\backuptest\go.bat', SW_SHOW, INFINITE, r);
[b]end[/b];
Can anyone give me some help in getting this working?
Thanks.