WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Logon Issues

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

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 
endif 

Answer:

EEEK. Let's look at what this script might be doing.
  1. 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.

  2. Assigning a directory to variable startup ...OK

  3. 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?

  4. The Filecopy looks more or less reasonable, assuming that the username variable was set correctly in the first place.

  5. What method is used to determine if the file copy really failed or not? Just clicking on the start menu may be insufficient.

  6. 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:   W13507
Filename:   Get Username and Copy Shortcut in Login Script.txt
File Created: 1999:04:15:16:54:30
Last Updated: 1999:04:15:16:54:30