Running a login script only when the script has changed

G

Guest

I have a login script assigned to users in Active Directory that connects to all the relevant printers. At the moment, this script runs every time users log in. It works, but it's a bit slow on the XP machines. It works by using "rundll32 printui.dll,PrintUIEntry"

I want to make the script run only when it's changed. I was thinking that if I write the date stamp of the file out into the user's roaming profile, I can see whether the script has changed since it was last run. If it hasn't, I can do a "goto :end" command

To do this I need to be able to

Output the time and date stamp of the batch file to a file in %userprofile%
Read the date stamp back in and compare it to the date stamp of the current file

Can anyone give me any pointers. Perhaps I'm approaching this entirely the wrong way, in which case I'd love to hear of any alternatives

Thank

Mr B
 
J

Jerold Schulman

I have a login script assigned to users in Active Directory that connects to all the relevant printers. At the moment, this script runs every time users log in. It works, but it's a bit slow on the XP machines. It works by using "rundll32 printui.dll,PrintUIEntry".

I want to make the script run only when it's changed. I was thinking that if I write the date stamp of the file out into the user's roaming profile, I can see whether the script has changed since it was last run. If it hasn't, I can do a "goto :end" command.

To do this I need to be able to:

Output the time and date stamp of the batch file to a file in %userprofile%.
Read the date stamp back in and compare it to the date stamp of the current file.

Can anyone give me any pointers. Perhaps I'm approaching this entirely the wrong way, in which case I'd love to hear of any alternatives.

Thanks

Mr B

Why not may it self generating.

In the script:

If not exist "%userprofile%\logondate.log" set old=none&goto record
for /f "Tokens=*" %%a in ('type "%userprofile%\logondate.log"') do (
set old=%%a
)
:record
for /f "Tokens=*" %%a in ('dir "%logonServer%\Netlogon\logon.bat^|findstr /i /L
/c:"logon.bat"') do (
set new=%%a
)
if /i "%old%" EQU "%new%" go to :EOF
@echo %new% > "%userprofile%\logondate.log"
rundll32 printui.dll,PrintUIEntry .....



Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
W

William Hymen

Impressive, but almost completely unreadable.
A few code comments would help!

Pure Personal Opinion....

to all the relevant printers. At the moment, this script runs every time
users log in. It works, but it's a bit slow on the XP machines. It works
by using "rundll32 printui.dll,PrintUIEntry".that if I write the date stamp of the file out into the user's roaming
profile, I can see whether the script has changed since it was last run. If
it hasn't, I can do a "goto :end" command.
 
J

Jerold Schulman

:: Test if this new script has run before and created logondate.log in the user profile
If not exist "%userprofile%\logondate.log" set old=none&goto record
:: Set old to the date / time of the previous logon.bat date / time
for /f "Tokens=*" %%a in ('type "%userprofile%\logondate.log"') do (
set old=%%a
)
:record
:: Set new to the current logon.bat date / time
for /f "Tokens=*" %%a in ('dir "%logonServer%\Netlogon\logon.bat^|findstr /i /L
/c:"logon.bat"') do (
:: The above 2 lines are one line (wrapped)
set new=%%a
)
if /i "%old%" EQU "%new%" go to :EOF
:: Write the 'new' logon.bat date / time
@echo %new% > "%userprofile%\logondate.log"
rundll32 printui.dll,PrintUIEntry .....



Impressive, but almost completely unreadable.
A few code comments would help!

Pure Personal Opinion....


to all the relevant printers. At the moment, this script runs every time
users log in. It works, but it's a bit slow on the XP machines. It works
by using "rundll32 printui.dll,PrintUIEntry".
that if I write the date stamp of the file out into the user's roaming
profile, I can see whether the script has changed since it was last run. If
it hasn't, I can do a "goto :end" command.


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
G

Guest

Jerold

Thank you very much for that. A little bit of fiddling later, I have the following

@echo of

If not exist "%userprofile%\printver.txt" set old=none&goto recor
for /f "Tokens=*" %%a in ('type "%userprofile%\printver.txt"') do
set old=%%


:recor
for /f "Tokens=*" %%a in ('dir %~dp0^|findstr /L /I /c:"printers.bat"') do
set new=%%

if "%old%"=="%new% " goto en

echo %new% > "%userprofile%\printver.txt

rundll32 printui.dll,PrintUIEntry /in /n \\printserver\printer
rem and all the other printers....

:en

I found that the %old% value had a space appended to the end, so when I did the comparison, it always returned false. I appended a space to the %new% side of the comparison to make it match

I also changed the order of the parameters on findstr and it seems to work perfectly now

Thanks again for all your help

Mr B
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top