Solved

Startup script for terminal users

Posted on 2011-02-15
21
1,169 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:victordr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 5
  • 3
  • +1
21 Comments
 

Author Comment

by:victordr
ID: 34899334
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
 
LVL 5

Expert Comment

by:Eduardo Goicovich
ID: 34899355
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
 
LVL 7

Expert Comment

by:holthd
ID: 34899376
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:victordr
ID: 34899420
Is will just be a .lnk file. Will this still work?
0
 
LVL 3

Expert Comment

by:rxdeath
ID: 34899427
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
 

Author Comment

by:victordr
ID: 34899828
It isn't launching the .lnk file i have in the user's profile with your script holthd
0
 

Author Comment

by:victordr
ID: 34900262
belfegor:
 I tried your code also and it isn't working.

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

Is this correct?
0
 
LVL 3

Expert Comment

by:rxdeath
ID: 34900361
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
 

Author Comment

by:victordr
ID: 34900381
I have to edit 48 user's to make this change though.
0
 
LVL 3

Expert Comment

by:rxdeath
ID: 34900414
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
 

Author Comment

by:victordr
ID: 34900445
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
 
LVL 7

Expert Comment

by:holthd
ID: 34902189
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
 
LVL 7

Expert Comment

by:holthd
ID: 34902206
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
 

Author Comment

by:victordr
ID: 34906229
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
 

Author Comment

by:victordr
ID: 34915387
Now i also need to to auto-start IE and have it minimized.. Can i add this to this script?
0
 

Author Comment

by:victordr
ID: 34918737
Now i am getting this error.
startuperror.JPG
0
 

Author Comment

by:victordr
ID: 34927972
Would this be because i have the terminal server so locked down?
0
 

Author Comment

by:victordr
ID: 34928984
Can someone please help me with this? I need to get this resolved? Thank you.
0
 
LVL 7

Accepted Solution

by:
holthd earned 500 total points
ID: 34935282
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
 
LVL 7

Expert Comment

by:holthd
ID: 34935301
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
 

Author Comment

by:victordr
ID: 34942917
I resovled it on my own. I had to use CSCRIPT C:\path to vbs file.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question