Startup script for terminal users

I have a 2003 terminal server setup so when a user logins to RDP it runs the following program. What i am looking to do is set it so it runs a script that will launch a shortcut from this user's roaming profile instead.

 What would be the best way to do this

 I am also having an issue when they close the application, sometimes it doesn't logoff.



 GPO Setting
victordrAsked:
Who is Participating?
 
holthdCommented:
Sorry for the late response Victor. Please allow me to clearify my script for you with regards to your questions.
1. The FILE variable does not care which extention the file has. It behaves "identically" to putting the same string/sentence into the RUN (Start | Run) box in Windows.
2. The error message you are getting is not a script run-time error at least. Script run-time errors always have the title "Windows Script Host". Please consult with the Application and System event log on the Terminal Server.
2.1 I'd suggest checking A) the file permission, B) If access to C:\ is disabled through policy and C) that Software Restriction policy does not block this scenario if enabled.
3. Yes Internet Explorer can be opened as well. Please see the updated script below and modify the file path's/commands as you wish.
Const WindowHidden = 0
Const WindowVisible = 1
Const WindowMinimized = 2
Const WaitForProcessTrue = 1
Const WaitForProcessFalse = 0
Set obj_Shell = WScript.CreateObject("WScript.Shell")
Set obj_FSO = WScript.CreateObject("Scripting.FileSystemObject")
Set obj_Net = WScript.CreateObject("WScript.Network")
strUserName = obj_Net.UserName

'Copy the line below and modify to start other files as well. Behaves the same as Start | Run in Windows.
Run "\\server\folder$\" & strUserName & "\folder\file.lnk", WindowVisible, WaitForProcessFalse
'Copy the line below and modify to start other files as well. Behaves the same as Start | Run in Windows.
Run "C:\Program Files\Internet Explorer\iexplore.exe", WindowMinimized, WaitForProcessFalse

Function Run(str_Cmd, windowBehaviour, WaitOrProceed)
	If Instr(str_Cmd, " ") <> 0 Then str_Cmd = Chr(34) & str_Cmd & Chr(34) '(Enclose command in apostrophe (") if containing spaces ( ))
	If obj_FSO.FileExists(str_Cmd) = TRUE Then
		obj_Shell.Run str_Cmd, windowBehaviour, WaitOrProceed
	End IF
End Function

Set obj_Shell = Nothing
Set obj_FSO = Nothing
Set obj_Net = Nothing

Open in new window

0
 
victordrAuthor Commented:
Event Type:      Information
Event Source:      UPHClean
Event Category:      None
Event ID:      1401
Date:            2/15/2011
Time:            1:19:37 PM
User:            DOMAIN\Extrude1
Computer:      TS1
Description:
The following handles in user profile hive DOMAIN\Extrude1 (S-1-5-21-366032897-207377934-928725530-4762) have been remapped because they were preventing the profile from unloading successfully:
 
Rtvscan.exe (2100)
  HKCU\Software\Symantec\Symantec Endpoint Protection\AV\Custom Tasks (0xa64)

I just loaded UPHClean and got this in the event log.
0
 
Eduardo GoicovichIT ConsultantCommented:
make a logon script file named roamingStartUp.vbs

'-----code----
Dim strUser
Dim WshNetwork ,WshShell
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")

strUser = WshNetwork.UserName 'connected user

WshShell .Run PathToProfileRoot &   strUser & "\Application.lnk"  

Set WshShell =Nothing
Set WshNetwork =Nothing


0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
holthdCommented:
Try this code. Change the variable "EXECUTABLE" and "ARGUMENTS" to reflect the path to the executable and passed arguments. Leave ARGUMENTS like it is if you don't intend to pass arguments.
'Path to Navision. %USERNAME% will automatically be replaced with correct value
EXECUTABLE = "\\server\folder$\%username%\folder\file.exe"
ARGUMENTS = ""

int_ReturnCode = 0
Set obj_Shell = WScript.CreateObject("WScript.Shell")
Set obj_FSO = WScript.CreateObject("Scripting.FileSystemObject")
str_path = fun_StringWithUsername(EXECUTABLE) '(fix %username% if present)
If ARGUMENTS <> "" Then
	str_RunCmd = str_path & " " & ARGUMENTS
Else
	str_RunCmd = str_path
End If

If obj_FSO.FileExists(str_File) = true Then
	obj_Run = obj_Shell.Run(str_RunCmd, 1, false)
	If varType(obj_Run) = 2 Then int_ReturnCode = obj_Run
End If
Wscript.Quit(int_ReturnCode)

Function fun_StringWithUsername ( str_StringTemp )
	str_StringTemp = LCase(str_StringTemp)
	If InStr(str_StringTemp, " ") <> 0 Then str_StringTemp = Chr(34) & str_StringTemp & Chr(34) '(enclose in apostrophes (") if string contains space(s))
	Set obj_Net = WScript.CreateObject("WScript.Network")
	str_UserName = obj_Net.UserName
	If InStr(str_StringTemp, "%username%") <> 0 Then
		fun_StringWithUsername = Replace(str_StringTemp, "%username%", str_UserName)
	Else
		fun_StringWithUsername = str_StringTemp
	End If
End Function

Open in new window

0
 
victordrAuthor Commented:
Is will just be a .lnk file. Will this still work?
0
 
rxdeathCommented:
i do it in the users profile in AD under environment using the start following program at login our two entries are

program file name
C:\WINDOWS\system32\telnet.exe telnet.xxxxxx.com

and start in
C:\WINDOWS\system32
0
 
victordrAuthor Commented:
It isn't launching the .lnk file i have in the user's profile with your script holthd
0
 
victordrAuthor Commented:
belfegor:
 I tried your code also and it isn't working.

WshShell.Run "\\server2\profiles" &   strUser & "\navilive.lnk"  

Is this correct?
0
 
rxdeathCommented:
did you try my way?  i know it works, we use it for half of our users.  if you need gp for some reason ok, but i know this works
0
 
victordrAuthor Commented:
I have to edit 48 user's to make this change though.
0
 
rxdeathCommented:
lol.  48 is nothing. i see what you're saying though, but we have like 2000 users and when i changed our mail from mail.domain.com to domain.com, i had to type every email address over manually, so i appreciate whaty ou'er saying.  you know whats best though man, if you're under a time crunch, try that and then see if you can fix it with gpo, otherwise good luck.
0
 
victordrAuthor Commented:
I still need a script though. It has to figure out what the username is to put it to the correct .lnk file in the correct profile folder.
0
 
holthdCommented:
victordr, sorry the script did not work but it's ok when I use it. Try the below script. Edit the "FILE" variable to match the path to the shortcut. Notice that the script will give you a box saying whether or not it found the file or not. Remove the lines starting with "Wscript.Echo" before putting into production.
If you still have problems please post an example path to one of the files you are trying to start.

NB! You must put this in as a LOGON SCRIPT not STARTUP SCRIPT. You're sure your GPO's are setup correctly?

-Daniel
Const WindowVisible = 1
Const WindowHidden = 0
Const WaitForProcessTrue = 1
Const WaitForProcessFalse = 0
Set obj_Shell = WScript.CreateObject("WScript.Shell")
Set obj_FSO = WScript.CreateObject("Scripting.FileSystemObject")
Set obj_Net = WScript.CreateObject("WScript.Network")
strUserName = obj_Net.UserName

FILE = "\\server\folder$\" & strUserName & "\folder\file.lnk"

If obj_FSO.FileExists(FILE) = TRUE Then
	Wscript.Echo FILE & " found!"
	obj_Shell.Run FILE, WindowVisible, WaitForProcessFalse
Else
	Wscript.Echo FILE & " WAS NOT FOUND!!!"
End IF

Open in new window

0
 
holthdCommented:
Below is a cleaned up version that does not give you any messages. Once you have tested with the script in my previous post and got it working you just overwrite the line "FILE = ..." in this script and you're good to go.

-Daniel
Const WindowVisible = 1
Const WindowHidden = 0
Const WaitForProcessTrue = 1
Const WaitForProcessFalse = 0
Set obj_Shell = WScript.CreateObject("WScript.Shell")
Set obj_FSO = WScript.CreateObject("Scripting.FileSystemObject")
Set obj_Net = WScript.CreateObject("WScript.Network")
strUserName = obj_Net.UserName

FILE = "\\server\folder$\" & strUserName & "\folder\file.lnk"

If obj_FSO.FileExists(FILE) = TRUE Then
	obj_Shell.Run FILE, WindowVisible, WaitForProcessFalse
End IF

Set obj_Shell = Nothing
Set obj_FSO = Nothing
Set obj_Net = Nothing

Open in new window

0
 
victordrAuthor Commented:
Daniel,

 The orginal script is is set to run an .EXE correct? So using a lnk file wouldn't work. I am just trying to understand the code and make sure i am reading it correctly.
0
 
victordrAuthor Commented:
Now i also need to to auto-start IE and have it minimized.. Can i add this to this script?
0
 
victordrAuthor Commented:
Now i am getting this error.
startuperror.JPG
0
 
victordrAuthor Commented:
Would this be because i have the terminal server so locked down?
0
 
victordrAuthor Commented:
Can someone please help me with this? I need to get this resolved? Thank you.
0
 
holthdCommented:
Just a side note; the third parameter WaitForProcessTrue and WaitForProcessFalse dictates whether or not the script will wait for the executed file (thread) to exit (terminate). If WaitForProcessTrue is used for opening Internet Explorer you will experience a 10 minute (GPO default) delay because the script waits for someone or something to close Internet Explorer manually. Since Windows Explorer is not loaded by default before all logon scripts has finished nobody is able to close the application and you'll get a severe delay.
If WaitForProcessFalse is used it will only slam the command into Run and then proceed with whatever comes next in the script. Be aware of this setting.

-Daniel
0
 
victordrAuthor Commented:
I resovled it on my own. I had to use CSCRIPT C:\path to vbs file.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.