Get Username and FileCopy Shortcut in Login Script
Keywords: shortcutdir shortcut LNK filecopy
Question:
The following code runs fine after login is complete but not during the login process.During login, debug always reports fileexist() as 0, (whether or not the file actually exists) and filecopy() as 1, (but never successfully copies the file. PS, all variables seem to be initialized properly in both cases. What's up Doc?
username=environment("username") STARTUP="C:\WINDOWS\Profiles\%USERNAME%\Start Menu\Programs\StartUp" popup=fileexist("STARTUP\winpopup.lnk") if popup == 0 dirchange("k:\") filecopy ("winpopup.lnk", STARTUP, @false) else endifAnswer:
EEEK. Let's look at what this script might be doing.
- Problem #1: Get the username environment variable. Depending on how it is set, the variable may not be established at that point in the login.
- Assigning a directory to variable startup ...OK
- Doing a FileExist on the file "STARTUP\winpopup.lnk" in whatever current random directory you might be in. STARTUP is a literal in this case as it is not surrounded by % signs. You change that to:
popup=fileexist("%STARTUP%\winpopup.lnk")In addition, do a FileExist on lnk files "shortcut" -- this function looks thru the lnk file and tests the existence of the target file (rather than just looking for the LNK file itself). Is that what you wanted?
- The Filecopy looks more or less reasonable, assuming that the username variable was set correctly in the first place.
- What method is used to determine if the file copy really failed or not? Just clicking on the start menu may be insufficient.
- I'm Also scared about copying the lnk file. I think it might copy the target rather than the LNK file itself. The system gets real confused. I would recommend using the ShortCutMake function.
See revised script below:
DEBUG(1) username=environment("username") STARTUP="C:\WINDOWS\Profiles\%USERNAME%\StartMenu\Programs\StartUp" ;OR MAYBE TRY INSTEAD STARTUP=ShortcutDir("StartUp") popup=fileexist("%STARTUP%\winpopup.lnk") if popup == 0 ShortCutMake(...see docs...) endif
Article ID: W13507Filename: Get Username and Copy Shortcut in Login Script.txt