InTheFlow Posted January 31, 2007 Share Posted January 31, 2007 (edited) I just searched this forum & google for the answer but didn't find it. I know that using the group policy I can set a logoff script to execute every time a user of an XP Pro machine logs off.However, I want it to run a log off script for only one user profile. Can this be done somehow or am I wasting my time?I have a startup script which net stops both instances of folding@home when I log onto my gaming profile. When logging back off, I want it to net start both of them again but NOT do it when I log out of my other profiles.Is that possible? If so, please share how. EDIT: I also should add that this is a single XP Pro box on a workgroup. There is no server. Thx.EDIT: Tried to add 'resolved' to the title of this post. Edited February 4, 2007 by InTheFlow Link to comment Share on other sites More sharing options...
nmX.Memnoch Posted January 31, 2007 Share Posted January 31, 2007 You could use a KIX32 script and do a user name check:If @USERID = "username" Shell '%COMSPEC% /C net start "service 1"' Shell '%COMSPEC% /C net start "service 2"'EndIfYou could even get fancy with some WMI code in there that would check to see if the services were already started first. Link to comment Share on other sites More sharing options...
rehbar Posted January 31, 2007 Share Posted January 31, 2007 (edited) Yor pc on network or single? And you want's to log off your pc or network? if your own PC then create batch file and type below words in it.shutdown -f -t00save this batch file and run. Edited January 31, 2007 by rehbar Link to comment Share on other sites More sharing options...
InTheFlow Posted February 1, 2007 Author Share Posted February 1, 2007 You could use a KIX32 script and do a user name check:If @USERID = "username" Shell '%COMSPEC% /C net start "service 1"' Shell '%COMSPEC% /C net start "service 2"'EndIfYou could even get fancy with some WMI code in there that would check to see if the services were already started first.Thanks for the idea nmX.Memnoch...I don't know anything about kix32 yet but I'll study up, tinker around and see if I can get it to work. If not, I'll ask for some more help. Yor pc on network or single? And you want's to log off your pc or network? if your own PC then create batch file and type below words in it.shutdown -f -t00save this batch file and run.Thanks for the help rehbar. I actually don't want to shut down the entire PC though. Just log out of a single user account and then have the system re-start two services. Link to comment Share on other sites More sharing options...
nmX.Memnoch Posted February 1, 2007 Share Posted February 1, 2007 You could use a KIX32 script and do a user name check:If @USERID = "username" Shell '%COMSPEC% /C net start "service 1"' Shell '%COMSPEC% /C net start "service 2"'EndIfYou could even get fancy with some WMI code in there that would check to see if the services were already started first.Thanks for the idea nmX.Memnoch...I don't know anything about kix32 yet but I'll study up, tinker around and see if I can get it to work. If not, I'll ask for some more help. KiX can be pretty powerful. Just let me know if you have any questions and I'll see if I can provide some code examples. There's also a wealth of information on the KiXtart website, as well as the following sites:http://www.adminscripteditor.com/scriptlibrary/browse.asphttp://www.kixtart.org/udf/http://www.scriptlogic.com/kixtart/ Link to comment Share on other sites More sharing options...
InTheFlow Posted February 1, 2007 Author Share Posted February 1, 2007 KiX can be pretty powerful. Just let me know if you have any questions and I'll see if I can provide some code examples. There's also a wealth of information on the KiXtart website, as well as the following sites:http://www.adminscripteditor.com/scriptlibrary/browse.asphttp://www.kixtart.org/udf/http://www.scriptlogic.com/kixtart/Thanks! Link to comment Share on other sites More sharing options...
InTheFlow Posted February 1, 2007 Author Share Posted February 1, 2007 KiX can be pretty powerful. Just let me know if you have any questions and I'll see if I can provide some code examples.Ok, a couple issues/questions...First, what exactly is %COMSPEC% /c doing? I can't find that command anywhere and its driving me nuts. Now, if I create a logoff.kix file with the below in it:If @USERID = "comp1" Shell '%COMSPEC% /c net start "FAH@E:+Program Files+Folding@Home+F@H1+FAH504-Console.exe"' ; at the end of this line is a double quote followed by a single quote Shell '%COMSPEC% /c net start "FAH@E:+Program Files+Folding@Home+F@H2+FAH504-Console.exe"' ; at the end of this line is a double quote followed by a single quoteEndIfAfter exectuing the .kix file with kix32.exe, it gives me an error stating: "The service name is invalid"However, I have a foldingstart.bat file which works perfectly to start the services. The contents of it are below:net start "FAH@E:+Program Files+Folding@Home+F@H1+FAH504-Console.exe"net start "FAH@E:+Program Files+Folding@Home+F@H2+FAH504-Console.exe"So, why is it telling me the service name is invalid when it must be correct since it works in my .bat file?Thanks. Link to comment Share on other sites More sharing options...
nmX.Memnoch Posted February 2, 2007 Share Posted February 2, 2007 (edited) First, what exactly is %COMSPEC% /c doing? I can't find that command anywhere and its driving me nuts. That does nothing more than start a cmd.exe process. %COMSPEC% is an operating system variable like %SystemRoot% (your Windows directory) or %SystemDrive% (the drive Windows is installed on).If @USERID = "comp1" Shell '%COMSPEC% /c net start "FAH@E:+Program Files+Folding@Home+F@H1+FAH504-Console.exe"' ; at the end of this line is a double quote followed by a single quote Shell '%COMSPEC% /c net start "FAH@E:+Program Files+Folding@Home+F@H2+FAH504-Console.exe"' ; at the end of this line is a double quote followed by a single quoteEndIfAfter exectuing the .kix file with kix32.exe, it gives me an error stating: "The service name is invalid"However, I have a foldingstart.bat file which works perfectly to start the services. The contents of it are below:net start "FAH@E:+Program Files+Folding@Home+F@H1+FAH504-Console.exe"net start "FAH@E:+Program Files+Folding@Home+F@H2+FAH504-Console.exe"So, why is it telling me the service name is invalid when it must be correct since it works in my .bat file?Thanks.KiX uses the @ symbol to identify built in variables that can be used. For instance, @USERID is the current users logon name, @WKSTA is the computer name, @DATE is the current date, @TIME is the current time, etc, etc. If you want to use "@" in a string you have to double it...like so:If @USERID = "comp1" Shell '%COMSPEC% /C START "" /WAIT net start "FAH@@E:+Program Files+Folding@@Home+F@@H1+FAH504-Console.exe"' Shell '%COMSPEC% /C START "" /WAIT net start "FAH@@E:+Program Files+Folding@@Home+F@@H2+FAH504-Console.exe"'EndIfNotice that I also added START "" /WAIT into the command. This basically forces cmd.exe (and in turn KiX) to wait until this command has finished processing before starting the next command. Edited February 11, 2007 by nmX.Memnoch Link to comment Share on other sites More sharing options...
InTheFlow Posted February 2, 2007 Author Share Posted February 2, 2007 KiX uses the @ symbol to identify built in variables that can be used. For instance, @USERID is the current users logon name, @WKSTA is the computer name, @DATE is the current date, @TIME is the current time, etc, etc. If you want to use "@" in a string you have to double it...like so:If @USERID = "comp1" Shell '%COMSPEC% /C START "" /WAIT net start "FAH@@E:+Program Files+Folding@@Home+F@@H1+FAH504-Console.exe"' Shell '%COMSPEC% /C START "" /WAIT net start "FAH@@E:+Program Files+Folding@@Home+F@@H2+FAH504-Console.exe"'EndIfNotice that I also added START "" /WAIT into the command. This basically forces cmd.exe (and in turn KiX) to wait until this command has finished processing before starting the next command.Thanks for the clarification on the @ symbol. I had read that you have to double those when using them in a string but didn't make the connection. Thanks!Where are you getting the information about the START & /WAIT commands? I searched for both of them within Kixtart's command lists but can't find them. Is Kixtart interfacing with another set of commands that can be 'nested' within the .kix script? On to the current results...When I add the above code into the .kix file, go to the command line and type: "kix32 logoff.kix" and press enter, the commands execute successfully and start the two services. However, when I add the script to the User Group Policy it is not working. I hear the windows exit sound, a message displays saying: "running logoff scripts" and it then drops me back to the logon/welcome screen. If I go into another login, pull up task manager and look to see if the services were, in fact, started...they were not.So something isn't working properly. This is what I've tried on the group policy settings:First I go:run > gpedit.msc > User Configuration > Windows Settings > Scripts (Logon/Logoff) > Standard Tab > Double click "Logoff"I add 'c:\scripts\kix32.exe' to the script name lineUnder Script Parameters I enter: 'logoff.kix'I've also tried 'c:\scripts\kix32.exe logoff.kix' on the script name line & nothing in the parameters boxAnd 'c:\scripts\kix32 logoff.kix' on the script name line & nothing in the parameters box.All three attempts produced the same results as described above.I'm wondering if what is happeing is that once the windows exit sound has played it means the user is logged out and the script is running after that? If so, the script would not execute because the computer name would not be equal to "comp1".To test this I changed the logoff.kix script to:Shell '%COMSPEC% /C START "" /WAIT net start "FAH@@E:+Program Files+Folding@@Home+F@@H1+FAH504-Console.exe"' Shell '%COMSPEC% /C START "" /WAIT net start "FAH@@E:+Program Files+Folding@@Home+F@@H2+FAH504-Console.exe"'and then logged off thinking it should run regardless of which user was logged in. However, I got the same results as above.Am I entering the command into the logoff script name incorrectly?Thanks. Link to comment Share on other sites More sharing options...
nmX.Memnoch Posted February 3, 2007 Share Posted February 3, 2007 Where are you getting the information about the START & /WAIT commands? I searched for both of them within Kixtart's command lists but can't find them. Is Kixtart interfacing with another set of commands that can be 'nested' within the .kix script?The SHELL command in KiX allows you to shell other executables. In this case we are shelling out to a Command Prompt (%COMSPEC%). START is a command you can use in a Command Prompt environtment to control whether or not a script is instructed to wait on the command to complete or not. You can also use it to control the CPU priority of an application. Open a Command Prompt and type start /?. You'll see the list of available commands for START.When I add the above code into the .kix file, go to the command line and type: "kix32 logoff.kix" and press enter, the commands execute successfully and start the two services. Cool. However, when I add the script to the User Group Policy it is not working. I hear the windows exit sound, a message displays saying: "running logoff scripts" and it then drops me back to the logon/welcome screen. If I go into another login, pull up task manager and look to see if the services were, in fact, started...they were not.So something isn't working properly. This is what I've tried on the group policy settings:First I go:run > gpedit.msc > User Configuration > Windows Settings > Scripts (Logon/Logoff) > Standard Tab > Double click "Logoff"Hmmm...ok, we need to see what user context the logoff scripts run in. They should still run in the context of the user that was logged in since they're user logoff scripts. Make this change:run > gpedit.msc > User Configuration > Administrative Templates > System > Scripts >Set "Run logoff scripts visible" to EnabledAdd the following to the top of your logoff script so we can see what user the script is running as:? "@USERID"Sleep 10When it runs it will display the username that the script is running as, and pause for 10 seconds so you can see it. Make sure that it displays the same username as what you were just logged in with.I add 'c:\scripts\kix32.exe' to the script name lineUnder Script Parameters I enter: 'logoff.kix'That's the proper way to do it.I'm wondering if what is happeing is that once the windows exit sound has played it means the user is logged out and the script is running after that? If so, the script would not execute because the computer name would not be equal to "comp1".You should be checking for a user name, not a computer name. Make sure you have the user's name in the If line instead of the computer name.To test this I changed the logoff.kix script to:Shell '%COMSPEC% /C START "" /WAIT net start "FAH@@E:+Program Files+Folding@@Home+F@@H1+FAH504-Console.exe"'Shell '%COMSPEC% /C START "" /WAIT net start "FAH@@E:+Program Files+Folding@@Home+F@@H2+FAH504-Console.exe"'and then logged off thinking it should run regardless of which user was logged in. However, I got the same results as above.This kind of has me wondering if the system variables are still valid during the logoff process. We can test this next. Link to comment Share on other sites More sharing options...
InTheFlow Posted February 3, 2007 Author Share Posted February 3, 2007 nmX.Memnoch - thanks a million for all your help on this!If so, the script would not execute because the computer name would not be equal to "comp1".You should be checking for a user name, not a computer name. Make sure you have the user's name in the If line instead of the computer name.Even though I typed 'computer name' I meant 'user name' Hmmm...ok, we need to see what user context the logoff scripts run in. They should still run in the context of the user that was logged in since they're user logoff scripts. Make this change:run > gpedit.msc > User Configuration > Administrative Templates > System > Scripts >Set "Run logoff scripts visible" to EnabledAdd the following to the top of your logoff script so we can see what user the script is running as:? "@USERID"Sleep 10When it runs it will display the username that the script is running as, and pause for 10 seconds so you can see it. Make sure that it displays the same username as what you were just logged in with.I did all of the above and here is what happened: The same thing as before. As in I saw the message 'running logoff scripts' but never got a command box displaying anything...I add 'c:\scripts\kix32.exe' to the script name lineUnder Script Parameters I enter: 'logoff.kix'That's the proper way to do it.This got me to wondering so I checked to make sure it was still set up this way. It was actually all on the script name line. So, I switched it to match the above example and then it flashed a command box with an error instead of just saying it was 'running logoff scripts'.I logged off several more times and finally got the entire message. It said: 'Error Failed to find/open script [logoff.kix]!'That made me think that maybe it didn't know where the script was located at. So, I went back into the group policy's logoff section and added the path to the parameters line. Now, instead of just saying 'logoff.kix' it says: 'c:\scripts\logoff.kix'.After making that change, it worked...all of it. It automatically launches the services at logoff! Question: Is it normal to have to put the path on that line? It seems like it should automaticlly check for the script in the same folder that the kix32.exe is found...Now the next step is to enhance the script so that depending on which user is logging off, it will back up specific files/directories to another hard drive automaticaly. Would you recommend that I start my research on how to do that with kixart's copy command or use the shell command to use something from the command prompts? Link to comment Share on other sites More sharing options...
nmX.Memnoch Posted February 3, 2007 Share Posted February 3, 2007 nmX.Memnoch - thanks a million for all your help on this!No problem... Even though I typed 'computer name' I meant 'user name' I figured...I just wanted to be sure. That made me think that maybe it didn't know where the script was located at. So, I went back into the group policy's logoff section and added the path to the parameters line. Now, instead of just saying 'logoff.kix' it says: 'c:\scripts\logoff.kix'.I wondered about that...and it was going to be my next suggestion.Question: Is it normal to have to put the path on that line? It seems like it should automaticlly check for the script in the same folder that the kix32.exe is found...To be honest I have KIX32.EXE (and WKIX32.EXE) in my Windows directory so I've always specified the full path to the script itself.Now the next step is to enhance the script so that depending on which user is logging off, it will back up specific files/directories to another hard drive automaticaly. Would you recommend that I start my research on how to do that with kixart's copy command or use the shell command to use something from the command prompts?Personally, when I'm using KIX I use as much native code as I can (i.e. use KiX's COPY command instead of shelling it out). Now if you want to make the source and destination match exactly, I recommend giving XXCOPY a look. I use that for disk-to-disk backups with great results. Link to comment Share on other sites More sharing options...
InTheFlow Posted February 4, 2007 Author Share Posted February 4, 2007 Question: Is it normal to have to put the path on that line? It seems like it should automaticlly check for the script in the same folder that the kix32.exe is found...To be honest I have KIX32.EXE (and WKIX32.EXE) in my Windows directory so I've always specified the full path to the script itself.Now the next step is to enhance the script so that depending on which user is logging off, it will back up specific files/directories to another hard drive automaticaly. Would you recommend that I start my research on how to do that with kixart's copy command or use the shell command to use something from the command prompts?Personally, when I'm using KIX I use as much native code as I can (i.e. use KiX's COPY command instead of shelling it out). Now if you want to make the source and destination match exactly, I recommend giving XXCOPY a look. I use that for disk-to-disk backups with great results.Good stuff to know. I need the files copied so that they match the source but don't need to backup an entire drive. On the gaming profile for example, I want it to back up the savegame directory of the games I played provided that the contents of those folders changed. I'll look into Kix's copy command first to see if I can do it with that or not.Thanks again for the help! Link to comment Share on other sites More sharing options...
nmX.Memnoch Posted February 4, 2007 Share Posted February 4, 2007 If you only want to backup the saved game files you can either have it just copy the entire directory, or if it is the same file everytime you can have it use CompareFileTimes. There are several ways it can be done. Link to comment Share on other sites More sharing options...
InTheFlow Posted February 8, 2007 Author Share Posted February 8, 2007 If you only want to backup the saved game files you can either have it just copy the entire directory, or if it is the same file everytime you can have it use CompareFileTimes. There are several ways it can be done.I've been working on getting this part to work and am having some issues. Here is the additonal code I'm using:DEBUG "ON"$TQBackup = "V:\Data Backup\Game Backups" ;Titan Quest Backup LocationIf @USERID = "gaming" messagebox ("Beginning Test","alert", 48) $Result = CompareFileTimes("C:\Scripts\testfile.txt", $TQBackup + "\CHKFileDir\testfile.txt") ? IF $Result = 1 OR $Result = -3 messagebox ("Backing up Files Now..."+ @DATE,"alert", 48) ? COPY "C:\Scripts\testfile.txt" $TQBackup + "\CHKFileDir\" @error ? COPY "C:\Scripts\" $TQBackup + "\@date\" /s @error ? EndIF IF $Result = -1 messagebox ("Files are newer in target directory..." + @DATE,"alert", 48) EndIF IF $Result = 0 messagebox ("Files are exact matches in target & Backup directories..."+ @DATE,"alert", 48) EndIFENDIFNOTE: the '?', "@error", & Debug = "on" commands I have added so I can understand how this thing works better. What I'm trying to do is backup the save game files in a different directory every time. As in, I DON'T want it to overwrite the previous backup each time. That is why I have a CHKFileDir Directory and copy only one file to it. It acts as the always updated 'check file' which can be compared with the original.It is the 2nd copy command I'm having issues with & questions about (bolded & Italicied). Ideally, I'd like to have a directory created based on today's date. But because the @DATE thing (variable...command?) returns a value in the xxx/xx/xx format, a directory can't be created because those are illegal characters for both file and directory names.My first question is: Is there a way to get the response from @date formated in a different way? For example: xx-xx-xxxxIf so, this would resolve the issue.If not, then is there a way to change the target directory name incrementally each time it backs up the files?Also, I've done quite a bit of experimenting and as a result have a question about the copy command. If I type this into the .kix file:COPY "C:\Scripts\" $TQBackup + "\@day\" /s @error ?It creates a directory with today's day name without errorHowever, If I type this into the .kix file instead:COPY "C:\Scripts\" $TQBackup + "\@day\test\" /s @error ?orCOPY "C:\Scripts\" $TQBackup + "\@day\@day\" /s @error ?orCOPY "C:\Scripts\" $TQBackup + "\@day\test" /s @error ?orCOPY "C:\Scripts\" $TQBackup + "\@day\@day" /s @error ?I get a return error code of "3" which means directory not found. Why is that? My understanding of the copy command is that as long as I put a trailing "\" at the end, it should create the directory. Am I reaching a limitation within the kixtart program or formating it incorrectly? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now