Solved

Startup script for terminal users

Posted on 2011-02-15
21
1,140 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
  • 12
  • 5
  • 3
  • +1
21 Comments
 

Author Comment

by:victordr
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

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

Expert Comment

by:rxdeath
Comment Utility
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
Comment Utility
It isn't launching the .lnk file i have in the user's profile with your script holthd
0
 

Author Comment

by:victordr
Comment Utility
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
Comment Utility
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
Comment Utility
I have to edit 48 user's to make this change though.
0
 
LVL 3

Expert Comment

by:rxdeath
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:victordr
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Now i am getting this error.
startuperror.JPG
0
 

Author Comment

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

Author Comment

by:victordr
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I resovled it on my own. I had to use CSCRIPT C:\path to vbs file.
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
home folder path for users 4 46
Bizarre hard disk problem 15 67
Pass through dll 2 33
AD Replications issues 12 39
Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
Learn about cloud computing and its benefits for small business owners.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now