Link to home
Start Free TrialLog in
Avatar of IT Department
IT DepartmentFlag for Australia

asked on

Remove a shortcut via VB Script - Login Script

Hi All,

I am trying to remove a shortcut via VB Script. I can add the shortcut with no problem at all, just removing it is posing difficult. I have very limited VBS knowledge so hope this is just childs play for those in the know.

I am pasting the entire script here as it will probably make more sense.

The line in particular is 415.

            filesys.DeleteFile strAllUsersDesktop & "Interplan.*"

I am trying to remove Interplan.url and further below, add Interplan.lnk as we must have this shortcut open in internet Explorer not chrome, safari, ff etc..

I have tried putting in interplan.url with no joy, tried .* no joy, tried creating it's own area but then I get all kinds of errors about errors in lines etc.. so I am trying to tack onto an old part of the script where we were trying to remove a legacy piece of software.

Any help will be greatly appreciated.

Cheers


' option explicit

on error resume next

' Delcare variables
dim ADSysInfo                                                                       
dim computerName
dim MSIE
dim htmlHistory
dim userAccountDN
dim userDisplayName
dim objGroupList
dim objUser
dim location
dim objPrinterList

' Get arguments
location = lcase(wscript.arguments(0))

' Set default location if none passed
if len(location & "") = 0 then

	location = "main"

end if

' Create Objects
Set ADSysInfo = CreateObject("ADSystemInfo")
											   
' Get computer name
computerName = getComputerName()

' Get user account DN in active directory
userAccountDN = ADSysInfo.UserName

' Bind to user object in AD
Set objuser = GetObject("LDAP://" & userAccountDN)

' Get user's display name from Active Directory
userDisplayName = objUser.DisplayName

' Create dictionary object to hold user's groups
Set objGroupList = CreateObject("Scripting.Dictionary")

' Call subroutine to load users groups into dictionary object
call LoadGroups(objuser, objuser)

' Initialise HTML output
htmlhistory = ""

call configureOS

'call configureDatabases

call configureNetworkDrives

call configurePrinters

call configureDesktopShortcuts

call configureOfficeSuite

if location = "main" then

	writehtml "<center><div style=""spacing:20px;padding:20px;background-color:#0F6AAC;font-size:14pt""><center><b>You are now on the Shire of organisation network</b></center></div></center>"

end if

Wscript.Sleep 2000
writehtml ""

' Close Internet Explorer window
MSIE.Quit

' Destroy objects
set MSIE = nothing


sub configureOS()

	on error resume next

	' Declare variables
	dim wshShell

	' Create objects
	Set wshShell = createobject("wscript.shell")

	' Write heading to status web page
	writehtml "<b>Configuring Operating System</b><br>"

	' Configure date/time format
'        writehtml "Configuring Date/Time Format... "
'	wshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\International\iCountry", "61", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\International\iCountry", "61", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\International\iDate", "1", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\International\iTime", "0", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\International\Locale", "00000C09", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\International\s1159", "AM", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\International\s2359", "PM", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\International\sCountry", "Australia", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\International\sDate", "/", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\International\sLanguage", "ENA", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\International\sList", ",", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\International\sLongDate", "dddd, d MMMM yyyy", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\International\sShortDate", "d/MM/yyyy", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\International\sTime", ":", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\International\sTimeFormat", "h:mm:ss tt", "REG_SZ"
'	wshShell.ReservergWrite "HKEY_CURRENT_USER\Control Panel\International\iTimePrefix", "0", "REG_SZ"


'	showresult err.number
'	writehtml "<br>"
	wscript.sleep 250

	writehtml "Configuring Internet Explorer... "
        wshShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\servergis04\http", 2, "REG_DWORD"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\wa.gov.au\gis.kalbould\http", 2, "REG_DWORD"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\RunOnceComplete", '1, "REG_DWORD"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\RunOnceHasShown", '1, "REG_DWORD"      
	showresult err.number
	writehtml "<br>"

	writehtml "<br>"
	wscript.sleep 500

	' Destroy objects
	Set wshell = nothing


'This will configure TRIM1335 to display the correct Server name and port in turn, not prompting the user for a server / port
	writehtml "" & userDisplayName & " TRIM is being configured..."
	writehtml "<br>"
	writehtml "This script maps network drives and install printers, please be patient!!!"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Software\TOWER Software\TRIM5\Datasets\DefaultDB", "SM", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Software\TOWER Software\TRIM5\Datasets\LoadDefaultDB", 1, "REG_DWORD"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Software\TOWER Software\TRIM5\Datasets\SM\Name", "TRIM Production", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Software\TOWER Software\TRIM5\Datasets\SM\Primary", "serverdataent", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Software\TOWER Software\TRIM5\Datasets\SM\Secondary", "", "REG_SZ"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Software\TOWER Software\TRIM5\Datasets\SM\PrimaryPort", 1137, "REG_DWORD"
'	wshShell.RegWrite "HKEY_CURRENT_USER\Software\TOWER Software\TRIM5\Datasets\SM\SecondaryPort", 1137, "REG_DWORD"
	wshShell.RegWrite "HKEY_CURRENT_USER\Software\Hewlett-Packard\HP TRIM\DataPaths\TopDrawerDataPath", "H:\TRIM", "REG_SZ"
	wshShell.RegWrite "HKEY_CURRENT_USER\Software\Hewlett-Packard\HP TRIM\DataPaths\TRIMAppData", "H:\TRIM", "REG_SZ"
	wshShell.RegWrite "HKEY_CURRENT_USER\Software\Hewlett-Packard\HP TRIM\DataPaths\TRIMLocalAppData", "H:\TRIM", "REG_SZ"
	writehtml "<br>"
	showresult err.number
	writehtml "<br>"

	writehtml "<br>"
	wscript.sleep 1500

	' Destroy objects
	Set wshell = nothing



'This add on will rename the My Computer icon with the computer name
'	MCPath = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
'	WSHShell.RegWrite MCPath & "\", strComputer, "REG_SZ"

 writehtml "Set Time Server... "
	Dim wshell
	Set wshell = CreateObject("WScript.Shell")
	wshell.Run "%COMSPEC% /c net time \\domaincontroller01 /set /y > C:\Time.txt",0,TRUE
'	wshell.Run "%COMSPEC% /c net time \\domaincontroller02 /set /y > C:\Time.txt",0,TRUE
	set wshell = Nothing

	writehtml "<br>"
	wscript.sleep 100

' Configure Symprex..
	WshShell.Run "\\serverutil\symprex$\sign.exe", 1, True
	Wscript.Sleep 500

end sub

sub configureNetworkDrives()

	on error resume next

	writehtml "<b>Configuring Network Drives</b><BR>"

	' Map drives for all locations

        mapDrive "I:", "\\servergis04\ChampionSpace", "GIS Champion Workspace", "GG GIS Champions"
	mapDrive "L:", "\\serverdataent\LMSShare", "Links Modular Share", "PPRecCentre"
	mapDrive "S:", "\\serverprnfile\Data", "Shire Documents", ""
'	mapDrive "V:", "\\serverPRNFILE\STRATAGEM$", "Approve", "DL Planning"   
	mapDrive "U:", "\\serverGIS04\CADVolume$", "TS CADVolume", "GG TS CAD"  
	mapDrive "Y:", "\\organisation_Syn_Soft\Synsoft", "Synergy Data", ""
'	mapDrive "W:", "\\serverprnfile\Hawkeye", "DL Asset & Risk Management", "GG IT Department"
    mapDrive "Q:", "\\servergis04\New Aerials", "Aerials", "GG TS CAD"
	writehtml "<br>"
	Wscript.Sleep 500

end sub

sub configurePrinters

	on error resume next

	writehtml "<b>Configuring Network Printers</b><BR>"

	writehtml "Analysing Installed Printers... "

	' Call sub to load printer list into dictionary object
	call loadPrinterList

	showresult err.number
	writehtml "<br>"

	removePrinter "\\serverprnfile\FAXRoom Kyocera KM-6030 KX"
'	removePrinter "\\serverprnfile\RECORDS-CANON"
'	removePrinter "\\serverprnfile\RANGERS-KYOCERA"
'	removePrinter "\\serverprnfile\RANGERS"
'	removePrinter "\\serverprnfile\Copy1BindingRoom"
	removePrinter "\\serverprnfile\Reception"
	removePrinter "\\serverprnfile\DHVIC Copy"
'	removePrinter "\\serverprnfile\RICOH Aficio MP C3500 PCL 6"
	removePrinter "\\serverprnfile\MDCDR MP 2000 COPIER"
'	removePrinter "\\serverprnfile\MLCCopier"
	removePrinter "\\serverprnfile\A3 Lexmark C935 PS3"
'	removePrinter "\\serverprnfile\HP Color LaserJet CP4005 PCL 6"
	removePrinter "\\serverprnfile\ADMIN"
'	removePrinter "\\serverprnfile\ADMINT652"
	removePrinter "\\serverprnfile\FINANCE RICOH AP610N"
	removePrinter "\\serverprnfile\Building"
	removePrinter "\\serverprnfile\COMMUNITYDEV"
	removePrinter "\\serverprnfile\DIR DEVELOPMENT SERVICES"
	removePrinter "\\serverprnfile\Finance"
'	removePrinter "\\serverprnfile\Library Colour - Photo"
'	removePrinter "\\serverprnfile\LIBRARY-CANON"
	removePrinter "\\serverprnfile\LibraryKyoceraFS2020D"
	removePrinter "\\serverprnfile\PLANNING"
'	removePrinter "\\serverprnfile\Court House Laserjet MFP"
'	removeprinter "\\serverprnfile\Rangers"
	removePrinter "\\serverprnfile\Rates1"
'	removePrinter "\\servergis04\TS Colour Plotter"
'	removePrinter "\\serverprnfile\Accounts"
	removePrinter "\\serverprnfile\TECHSVCS"
	removePrinter "\\serverprnfile\IT"
'	removePrinter "\\serverprnfile\Receipt1"
'	removePrinter "\\serverprnfile\Receipt2"
'	removePrinter "\\serverprnfile\Receipt3"
	removePrinter "\\serverprnfile\Kyocera FS-2020D"
	removePrinter "\\serverprnfile\MLC C543DN"
'	removePrinter "\\serverprnfile\Faxroomcanon"
	removePrinter "\\serverpfnrile\Techsvcslex"
	removePrinter "\\serverprnfile\HumanResFS2020D"
'	removePrinter "\\serverprnfile\DEPOTCOPIER"


	connectPrinter "PPDevelopmentServices","\\serverprnfile\PlanningT652", "\\serverprnfile\PlanningT652"
	connectPrinter "PPDevelopmentServices","\\serverprnfile\BuildingT652", "\\serverprnfile\BuildingT652"
	connectPrinter "PPDevelopmentServices","\\serverprnfile\PandDT652", "\\serverprnfile\PandDT652"

	connectPrinter "PPCorporateCEO","\\serverprnfile\ADMINT652", "\\serverprnfile\ADMINT652"
	connectPrinter "PPCorporateCEO","\\serverprnfile\CREDITORS PRINTER", "\\serverprnfile\Finance"
	connectPrinter "PPCorporateCEO","\\serverprnfile\CORPORATE COLOUR HP", "\\serverprnfile\CorpHPColorL"

	connectPrinter "PPReception","\\serverprnfile\RECEPTION COPIER", "\\serverprnfile\Reception"
	connectPrinter "PPReception","\\serverprnfile\RECEIPT PRINTER 1", "\\serverprnfile\Receipt1"
	connectPrinter "PPReception","\\serverprnfile\RECEIPT PRINTER 2", "\\serverprnfile\Receipt2"
	connectPrinter "PPReception","\\serverprnfile\RECEIPT PRINTER 3", "\\serverprnfile\Receipt3"
	connectPrinter "PPHumanRes","\\serverprnfile\HumanResT652", "\\serverprnfile\HumanResT652"
	connectPrinter "PPCorporateRRR","\\serverprnfile\Accounts", "\\serverprnfile\Accounts"
	connectPrinter "PPCorporateRRR","\\serverprnfile\RATES PRINTER", "\\serverprnfile\RatesT652"
	connectPrinter "PPCorporateRRR","\\serverprnfile\CORPORATE COLOUR HP", "\\serverprnfile\CorpHPColorL"
	connectPrinter "PPRecords","\\serverprnfile\RECORDS-CANON", "\\serverprnfile\RECORDS"
	connectPrinter "PPCorporateRangers","\\serverprnfile\RANGERS-COPIER", "\\serverprnfile\RANGERS-COPIER"

	connectPrinter "PPCommunityService","\\serverprnfile\CommunityDevT652", "\\serverprnfile\CommunityDevT652"
	connectPrinter "PPCommunityService","\\serverprnfile\ADMINT652", "\\serverprnfile\ADMINT652"

	connectPrinter "PPTechnicalAdmin","\\serverprnfile\TECHSVCS", "\\serverprnfile\TECHSVCS"
	connectPrinter "spOCEPlotter","\\servergis04\TECH SERVICES PLOTTER", "\\servergis04\TSColourPlot"
	connectPrinter "PPTSExec","\\serverprnfile\TSExecT652", "\\serverprnfile\TSExecT652"

	connectPrinter "PPAdminBuilding","\\serverprnfile\Copy1BindingRoom", "\\serverprnfile\Copy1BindingRoom"
	connectPrinter "PPAdminBuilding","\\serverprnfile\FAXROOMCANON", "\\serverprnfile\FAXRoomCanon"
	connectPrinter "PPAdminBuilding","\\serverprnfile\RECORDS-CANON", "\\serverprnfile\RECORDS"

	connectPrinter "PPDonga","\\serverprnfile\TECHSVCS-CANON", "\\serverprnfile\TECHSVCS"


	connectPrinter "PPAccountant","\\serverprnfile\accountant", "\\serverprnfile\accountant"

	connectPrinter "PPLibrary","\\serverprnfile\LIBRARY-CANON", "\\serverprnfile\LIBRARY"
	connectPrinter "PPLibrary","\\serverprnfile\LibraryT652", "\\serverprnfile\LibraryT652"
	connectPrinter "PPRecCentre","\\serverprnfile\REC CENTRE COPIER", "\\serverprnfile\MLCCopier"
	connectPrinter "PPRecCentre","\\serverprnfile\REC CENTRE COPIER", "\\serverprnfile\MLC C543DN"
	connectPrinter "PPDepot","\\serverprnfile\DEPOTCOPIER", "\\serverprnfile\DEPOTCOPIER"

	writehtml "Setting Default Printer... "
	
	setDefaultPrinter "dfpDIRDEV", "\\serverprnfile\PandDT652", "\\serverprnfile\PandDT652"
	setDefaultPrinter "dfpADMIN", "\\serverprnfile\ADMINT652", "\\serverprnfile\ADMINT652"
	setDefaultPrinter "dfpBUILDING", "\\serverprnfile\BuildingT652", "\\serverprnfile\BuildingT652"
	setDefaultPrinter "dfpCommunityDev", "\\serverprnfile\CommunityDevT652", "\\serverprnfile\CommunityDevT652"
	setDefaultPrinter "dfpFINANCE", "\\serverprnfile\FINANCE CREDITORS RICOH AP610N", "\\serverprnfile\Finance"
	setDefaultPrinter "dfpPLANNING", "\\serverprnfile\PlanningT652", "\\serverprnfile\PlanningT652"
	setDefaultPrinter "dfpRANGERS", "\\serverprnfile\RANGERS-KYOCERA", "\\serverprnfile\RANGERS"
	setDefaultPrinter "dfpRATES", "\\serverprnfile\RATES RICOH SP4110N", "\\serverprnfile\Ratest652"
	setDefaultPrinter "dfpRECEPTION", "\\serverprnfile\RECEPTION RICOH MP2000 COPIER", "\\serverprnfile\Reception"
	setDefaultPrinter "dfpHUMANRES", "\\serverprnfile\HumanResT652", "\\serverprnfile\HumanResT652"
	setDefaultPrinter "dfpACCOUNTS", "\\serverprnfile\ACCOUNTS HP LaserJet P4010_P4510", "\\serverprnfile\accounts"
	' Records Printer is installed Locally	
'	setDefaultPrinter "dfpRECORDS", "\\serverprnfile\RECORDS-CANON", "\\serverprnfile\RECORDS"

	setDefaultPrinter "dfpDepot", "\\serverprnfile\DEPOTCOPIER", "\\serverprnfile\DEPOTCOPIER"
	setDefaultPrinter "dfpLibrary", "\\serverprnfile\LibraryT652", "\\serverprnfile\LibraryT652"
	setDefaultPrinter "dfpRecCentre", "\\serverprnfile\REC CENTRE COPIER", "\\serverprnfile\MLCCopier"
	setDefaultPrinter "dfpFaxRoomCopier", "\\serverprnfile\FAXROOMCANON", "\\serverprnfile\FAXROOMCANON"
	setDefaultPrinter "dfpDonga", "\\serverprnfile\TECHSVCS", "\\serverprnfile\TECHSVCS"
	setDefaultPrinter "dfpAccountant", "\\serverprnfile\Accountant", "\\serverprnfile\Accountant"
	writehtml "<font color=green>Success</font>"
	writehtml "<br>"

	writehtml "<br>"
	Wscript.Sleep 500


end sub



sub configureDesktopShortcuts()

On Error Resume Next
dim path
' Expand userprofile path to var path
path=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%")
dim objFSO
set objFSO=CreateObject("Scripting.FileSystemObject")
' check if the file exists at userprofile\filename.ext if not continue if does stop
If objFSO.FileExists(path & ("\AppData\Roaming\Microsoft\Windows\SendTo\HP TRIM.lnk")) = False Then
' copy file to userprofile\filename.ext
objFSO.CopyFile "\\domaincontroller01\netlogon\shortcuts\HP TRIM.lnk", path & "\AppData\Roaming\Microsoft\Windows\SendTo\HP TRIM.lnk"
' run file at userprofile\filename.ext
'Set WshShell = WScript.CreateObject("WScript.Shell")
'WshShell.Run(""""&path & "\filename.ext""")
End If



Dim strAllUsersProfile, strAllUsersStartup, strAllUserDesktop

	on error resume next

	writehtml "<b>Configure Desktop Shortcuts</b><br>"

Set objShell = CreateObject("WScript.Shell")

	strAllUsersProfile = objShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%")
	If InStr(LCase(strAllUsersProfile), LCase("documents and settings")) > 0 Then
		strAllUsersStartup = strAllUsersProfile & "\Start Menu\Programs\Startup\"
		strAllUsersDesktop = strAllUsersProfile & "\Desktop\"
	ElseIf InStr(LCase(strAllUsersProfile), LCase("programdata")) > 0 Then
		strAllUsersStartup = strAllUsersProfile & "\Microsoft\Windows\Start Menu\Programs\Startup\"
		strAllUsersDesktop = objShell.ExpandEnvironmentStrings("%PUBLIC%") & "\Desktop\"
	End If
' Copy Helpdesk shortcut to desktop
	writehtml "Copying NEW HELPDESK shortcut to " & strAllUsersDesktop & "... "
	copyFile "\\my.organisation.com\netlogon\shortcuts\HELPDESK SHIRE of organisation.url", strAllUsersDesktop
	showresult err.number
	writehtml "<br>"
	wscript.sleep 100

' Copy GIS shortcut to desktop
	writehtml "Copying GIS shortcut... to " & strAllUsersDesktop & "... "
	copyFile "\\my.organisation.com\netlogon\shortcuts\Intramaps 65 - GIS.lnk", strAllUsersDesktop
	showresult err.number
	writehtml "<br>"
	wscript.sleep 100

' Copy GIS shortcut to desktop
	writehtml "Copying GIS shortcut... to " & strAllUsersDesktop & "... "
	copyFile "\\my.organisation.com\netlogon\shortcuts\Intramaps75 - GIS.lnk", strAllUsersDesktop
	showresult err.number
	writehtml "<br>"
	wscript.sleep 100

' Copy Staff Service Portal shortcut to desktop   
	writehtml "Copying Staff Service Portal shortcut to " & strAllUsersDesktop & "... "
	copyFile "\\my.organisation.com\netlogon\shortcuts\Staff Service Portal.url", strAllUsersDesktop
	showresult err.number
	writehtml "<br>"
	wscript.sleep 100

' Copy Whereabouts shortcut to desktop   
'	writehtml "Copying Whereabouts shortcut to " & strAllUsersDesktop & "... "
'	copyFile "\\my.organisation.com\netlogon\shortcuts\Shortcut to Whereabouts.lnk", strAllUsersDesktop
'	showresult err.number
'	writehtml "<br>"
'	wscript.sleep 100

' Copy OWA shortcut to desktop   
	writehtml "Copying Outlook-Web shortcut to " & strAllUsersDesktop & "... "
	copyFile "\\my.organisation.com\netlogon\shortcuts\Webmail - Outlook Web Access.lnk", strAllUsersDesktop
	showresult err.number
	writehtml "<br>"
	wscript.sleep 100

' Remove Who's in from users PCs at sites with slow network links.

	'Check if user is a member of 'NoWhosIn' group
	if isMember(objUser, "NoWhosIn") then
	'Remove Who's In from startup
	writehtml "Remove Who's in from Startup if in group... "
	dim filesys
	Set filesys = CreateObject("Scripting.FileSystemObject") 
	If filesys.FileExists(strAllUsersStartup & "WhosIn.lnk") Then
  		filesys.DeleteFile strAllUsersStartUp & "WhosIn.lnk"
		filesys.DeleteFile strAllUsersDesktop & "WhosIn.lnk" 
		filesys.DeleteFile strAllUsersDesktop & "Interplan.*" 
  		Response.Write("Files deleted")
	End If 

'showresult err.number
	writehtml "<br>"
	wscript.sleep 250

	End if	

' Copy pwGen shortcut to desktop   
	writehtml "Copying pwGen shortcut to " & strAllUsersDesktop & "... "
	copyFile "\\my.organisation.com\netlogon\shortcuts\pwGenSystem.url", strAllUsersDesktop
	showresult err.number
	writehtml "<br>"
	wscript.sleep 100


' Copy Development Application Fees shortcut to non-Planning Staff desktops

	'Check if user is a member of 'Planning Development Fees' group
	if isMember(objUser, "Planning Development Fees") then
	'Planning Development Fees shortcut to desktop
	writehtml "Copying Application Development Fees shortcut to " & strAllUsersDesktop & "... "
	copyFile "\\my.organisation.com\netlogon\shortcuts\DA Fees.lnk", strAllUsersDesktop
	showresult err.number
	writehtml "<br>"
	wscript.sleep 250

	End if	


' Copy Development Application Fees shortcut to Planning Staff desktops

	'Check if user is a member of 'DL Planning' group
	if isMember(objUser, "DL Planning") then
	'Planning Development Fees shortcut to desktop
	writehtml "Copying Application Development Fees shortcut to " & strAllUsersDesktop & "... "
	copyFile "\\my.organisation.com\netlogon\shortcuts\DA Fees.lnk", strAllUsersDesktop
	showresult err.number
	writehtml "<br>"
	wscript.sleep 250

	End if	

' Copy Interplan Shortcut to desktops
	writehtml "Copying Interplan shortcut to " & strAllUsersDesktop & "... "
	copyFile "\\my.organisation.com\netlogon\shortcuts\Interplan.lnk", strAllUsersDesktop
	showresult err.number
	writehtml "<br>"
	wscript.sleep 100

end sub


sub configureOfficeSuite()

	on error resume next

	writehtml "<b>Configure Office & Other software....</b><br>"

		'	on error resume next
 
		'	' Define variables
		'	dim wshShell
		'	dim filesys

		'	' Create Objects
		'	set wshShell = wscript.CreateObject("wscript.shell")
		'	set fileSys = wscript.createObject("scripting.filesystemobject")
		
		'	writehtml "<b>Configuring Office Suite</b><br>"

		'	' Set Word Startup Path to Default
		'       writehtml "Configuring Word startup location... "

		'	' Check to see if startup path exists
		'	if filesys.folderexists(getUserProfilePath & "Application Data\Microsoft\Word") = false 'then

		'		filesys.CreateFolder(getUserProfilePath & "Application Data\Microsoft\Word")

		'	end if

		'	' Check to see if startup path exists
		'	if filesys.folderexists(getUserProfilePath & "Application Data\Microsoft\Word\STARTUP") = 'false 'then

		'		filesys.CreateFolder(getUserProfilePath & "Application Data\Microsoft\Word\STARTUP")

		'	end if
	
		'	wshshell.RegWrite "HKCU\Software\Microsoft\Office\11.0\Word\Options\STARTUP-PATH", 'getUserProfilePath & "Application Data\Microsoft\Word\STARTUP", "REG_EXPAND_SZ"
		'	showresult err.number
		'	writehtml "<br>"
		'	wscript.sleep 250

' Write AD Display Name to Office 2003 Username
	writehtml "Personalising Office... "
	Dim objADSystemInfo, objADsUser, objWord
	Set objADSystemInfo = CreateObject("ADSystemInfo")
	objADsUser = objADSystemInfo.UserName
	Set objUser = GetObject("LDAP://" & objADsUser)
	Set objWord = CreateObject("Word.Application")
	objWord.UserName = objUser.DisplayName
	objWord.Quit
	Wscript.Sleep 250
	writehtml "<br>"


' Configure TRIM Path..

'	writehtml "Configuring TRIM 1332 Datasets... "
 '	WshShell.Run "\\domaincontroller01\netlogon\PatchTrim1332.bat", 1, True
'	wshShell.RegWrite "HKEY_CURRENT_USER\Software\TOWER Software\TRIM5\Datasets", ""DefaultDB"="SM"", "REG_DWORD"
'	showresult err.number
'	writehtml "<br>"
'	Wscript.Sleep 500


' Cleanup Outlook temporary attachments
	writehtml "Cleaning up Outlook temp attachments... "
	call cleanupOutlookTempFolder
	showresult err.number
	writehtml "<br>"
	wscript.sleep 250

' Run Profileassist.bat from Netlogon
'Set WSHShell = CreateObject("Wscript.Shell")
'	writehtml "Running Profile Assist..."
'WSHShell.Run ("\\domaincontroller01\netlogon\profileassist.bat") 
'	showresult err.number
'	writehtml "<br>"
'	wscript.sleep 250

end sub

'''''''''''''''''''''''''''''''''''''''''''''
'' Supporting functions and routines below ''
'' Generally no editing should be required ''
'''''''''''''''''''''''''''''''''''''''''''''

sub unMapDrive(driveLetter)

	on error resume next

	' Delcare variables
	dim fileSys
	dim network

	' Create objects
	set fileSys = wscript.createObject("scripting.filesystemobject")
	set network = wscript.CreateObject("wscript.network")

	writehtml "Disconnecting " & driveLetter & "... "

	' Check if drive is connected
	if fileSys.driveexists(driveLetter) = true then 

		' Drive is connected, attempt to remove
		network.RemoveNetworkDrive driveLetter, True, True

		' Call subroutine to show operation result
		showresult err.number

	else

		' Drive is not connected - show N/A message
		writehtml "<font color=orange>N/A - Drive not connected</font>"

	end if

	writehtml "<br>"
	Wscript.Sleep 100

	' Destroy objects
	set network = nothing
	set filesys = nothing

end sub


' Sub connects or removes printer based on group membership
sub connectprinter(groupname, printerlocalname, printerpath)

	on error resume next

	' Declare variables
	dim network
	dim printserver

	' Create objects
	set network = wscript.CreateObject("wscript.network")

	printserver = serverNamefromUNC(printerpath)

        ' Check if user is a member of the printer user group
	if IsMember(objUser, groupname) Then
		
	     	' User is a member of printer user group

	         writehtml "Connecting " & printerpath & "... "

		' Check to see if printer is already installed or if the computer is the print server
		if objPrinterList.Exists(printerlocalname) = true or strcomp(computerName, printserver,1) = 0 then
	
			writehtml "<font color=blue>Already Connected</font>"

		else

			' Check if print server is online
			if isHostOnline(printserver) then		
			
				' Print server is online - Add printer
				network.AddWindowsPrinterConnection printerpath
				showresult err.number  

			else

				' Print server is not online, show warning message
				writehtml "<font color=orange>Cannot connect to print server</font>"

			end if 
		
		end if

		writehtml "<br>"
		wscript.sleep 250

	end if

	set network = nothing

end sub


sub removePrinter(localname)

	on error resume next

	' Declare variables
	dim network

	' Create objects
	set network = wscript.CreateObject("wscript.network")

	' Check to see if the printer is installed
	if objPrinterList.Exists(localname) then

		writehtml "Removing " & localname & "..." 
		network.RemovePrinterConnection localname
		showresult err.number 
		writehtml "<br>"
		wscript.sleep 250

	end if

	' Destroy objects
	set network = nothing

end sub


' Sub checks if the user is a member of AD group and sets the default printer
sub setdefaultprinter(groupname, localprintername, printerpath)

	on error resume next

	' Declare variables
	dim network
	dim printername
	dim printserver

	printserver = serverNamefromUNC(printerpath)
	printername = replace(localprintername, "\\" & printserver & "\", "")

	' Create objects
	set network = wscript.CreateObject("wscript.network")

        ' Check if user is a member of the default users group for this printer
	if IsMember(objUser, groupname) Then

		' User is a member of the group

		if strcomp(computerName, printserver,1) = 0 then

                	network.SetDefaultPrinter printername

		else

                	' Set default printer
			network.SetDefaultPrinter printerpath

		end if

	end if

	' Destroy objects
	set network = nothing

end sub


sub mapdrive(driveletter, path, description, adgroup)

	on error resume next

	' Declare variables
	dim network

	' Create objects
	set network = wscript.CreateObject("wscript.network")

	' Call sub to un map drive letter
	unMapDrive driveletter

	' Check to see if a conditional group has been passed
	if (len(adgroup & "") > 0 and isMember(objUser, adgroup)) or len(adgroup & "") = 0 then

		' User is a member of the group, or no group was specified
		writehtml "Mapping " & driveletter & " " & description & "..."

		' Map drive
		network.mapnetworkdrive driveletter, path, true

		' Show operation result
		showresult err.number

		writehtml "<br>"
       		WScript.Sleep 100

	end if

	' Destroy objects
	set network = nothing

end sub


sub writehtml(htmltext)
	
	on error resume next

	' Call window handler sub to make sure the window is ready
	call windowHandler

	' Output html to content div
	MSIE.Document.all.test1.InnerHTML = MSIE.Document.all.test1.InnerHTML & htmltext

	' Update html history with new output
	htmlhistory = htmlhistory & htmltext

	' Scroll content div 
	MSIE.Document.all.test1.scrolltop = 5000

end sub
 

sub windowhandler()

	on error resume next

	'Declare variables
	dim userGreetingText

	' Write an empty string to the script window
	MSIE.Document.all.test1.InnerHTML = MSIE.Document.all.test1.InnerHTML & ""

	' Check to see if there is an error, an error will be riased if the window has not been initialised or has been closed
	if err.number <> 0 then

		' Creator Internet Explorer object
		Set MSIE = CreateObject("InternetExplorer.Application")
	
		' Set Internet Explorer options
		MSIE.Navigate "\\domaincontroller01\NETLOGON\Logonscripts_Supportfiles\Paul's script\New Logon Script\logon template.html"
		MSIE.ToolBar = False
    		MSIE.Width = 460
     		MSIE.Height = 635
     		MSIE.Left = 25
     		MSIE.Top = 25
		MSIE.Resizable = False
		MSIE.StatusBar = False

		' Sleep for 100ms while Internet Explorer is loading
		Do While MSIE.Busy

			WScript.Sleep 100

		Loop

		' Build user greeting string with user's name, computer name and date/time
		usergreetingtext = "Good "

		If Hour(Now) < 12 Then

			usergreetingtext = usergreetingtext & "Morning"

		ElseIf Hour(Now) < 18 Then

			usergreetingtext = usergreetingtext & "Afternoon"

		Else

			usergreetingtext = usergreetingtext & "Evening"
     			        
		End If 

		usergreetingtext = usergreetingtext & ", <strong>" & userDisplayName & "</strong><br>"
                usergreetingtext = usergreetingtext & "You are using the computer <u><strong>" & computerName & "</strong></u><br>"
                usergreetingtext = usergreetingtext & "The time is <u><strong>" & formatdatetime(now(),1) & " " & formatdatetime(now(),3) & "</strong></u><br>"

		' Send user greeting string to template
		MSIE.document.all.greeting.InnerHTML = usergreetingtext

		' Update template with all script output so far
		MSIE.Document.all.test1.InnerHTML = htmlhistory


		end if

		' Set the IE window visible
		MSIE.Visible = True

'	end if

end sub	


sub showresult(errornumber)

	on error resume next

	' Check if an the error number passed indicates an error has occured
	if errornumber <> 0 then

		' Write failure message
		writehtml "<font color=white style=""background-color:red;""><strong>&nbsp;Failed&nbsp;</strong></font>"
		wscript.sleep 1000

		' Clear error status
		err.clear

	else

		' Write success message
		writehtml "<font color=green>Success</font>"

	end if

end sub




sub copyFile(sourcepath, destinationpath)

	on error resume next

	' Declare variables
	dim filesys
	dim file

	' Create objects
        set filesys = CreateObject("Scripting.FileSystemObject")

	' Bind to source file
        set file = filesys.getfile(sourcepath)

	' Copy file to destination
	file.copy(destinationpath)

	' Destroy objects
	set filesys = nothing

end sub


' Function returns the users local profile path from windows environment variables
' eg. C:\Documents and Settings\csa
function getUserProfilePath()

	on error resume next

	' Declare variables
	dim wshShell
	dim userProfilePath

	' Create objects
	Set wshShell = WScript.CreateObject("WScript.Shell")

	' Get profile path from windows environment string
       	userProfilePath = wshshell.expandenvironmentstrings("%USERPROFILE%") & "\"

	' Return user's profile path
	getUserProfilePath = userProfilePath

	' Destroy objects
	set wshShell = nothing

end function


sub cleanupOutlookTempFolder()

	on error resume next

	' Declare variables
	dim fileSys
	dim rootFolder
	dim wshShell
	dim objFolder
	dim objSubFolder
	dim colSubFolders
	dim folderName
	dim folderPath

	' Create objects
	set fileSys = createObject("scripting.filesystemobject")

	' Bind to Temporary Internet Files folder
	set rootFolder = fileSys.getFolder(getUserProfilePath() & "%TEMP%")
	set rootFolder = fileSys.getFolder(getUserProfilePath() & "Local Settings\Temporary Internet Files")
	set rootFolder = fileSys.getFolder(getUserProfilePath() & "Local Settings\Temp")
	set rootFolder = fileSys.getFolder(getUserProfilePath() & "LOCALS~1\Temp")

	' Bind to list of sub folders
	set colSubFolders = rootFolder.SubFolders

	' Loop through sub folders
	for each objSubFolder in colSubFolders

		' Get folder name and path
		folderName = objSubFolder.Name
		folderPath = objSubFolder.Path

		' Check if folder is and Outlook temporary item folder
		if left(folderName, 3) = "OLK" then

			' Delete the folder
			fileSys.deleteFolder folderPath, 1
			
		end if

	Next

	' Destroy objects
	set fileSys = nothing

end sub


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Function checks if a printer is installed on the client computer
'
' INPUTS
' PrinterPath - UNC path of printer, eg. \\file01\Admin
'
' OUTPUTS
' false - printer is not installed on the client computer
' true - printer is installed on the client computer
'
function isprinteronpc(printerpath)

	on error resume next

	' Check if the printerpath is contained within the list of printers installed on the computer
	if instr(lcase(listofprintersonpc), lcase(printerpath & ",")) > 0 then

        	' Printer is installed on local computer - Return true
		isprinteronpc = true

	else

        	' Printer is not installed on the local conputer - Return false
		isprinteronpc = false

	end if

end function


function isMember(objUser, groupName)
	
	on error resume next

	ismember = objGroupList.Exists(objUser.sAMAccountName & "\" & groupName)

end function


function getComputerName()

	on error resume next

	' Declare variables
	dim network

	' Create objects
	set network = wscript.CreateObject("wscript.network")
											   
	' Get computer name
	computerName = network.computername

	' Return computer name
	getComputerName = computerName

	' Desctruct objects
	set network = nothing

end function


sub loadPrinterList()

	on error resume next

	' Declare variables
	dim i
	dim printers
	dim printerpath
	dim network

	' Create network object
	set network = createobject("wscript.network")
        
	' Create dictionary object to hold list of printers
	set objPrinterList = createObject("Scripting.Dictionary")
	
	' Set object string comparison mode
	ObjPrinterList.CompareMode = vbTextCompare
	
	' Enumerate printers
	set printers = network.enumprinterconnections
	
	' Loop through list of printers
	for i = 0 to printers.count - 1 step 2
	
		printerpath = printers.item(i+1)

		' Check if printer is a network printer
		if instr(printerpath, "\\") > 0 then

			' Add printer path to dictionary object
			objPrinterList.Add printerpath, printerpath

		end if
	
	next

end sub


Sub LoadGroups(objPriObject, objADSubObject)

	on error resume next

	' Recursive subroutine to populate dictionary object objGroupList.

	dim colstrGroups
	dim objGroup
	dim j

	objGroupList.CompareMode = vbTextCompare
	colstrGroups = objADSubObject.memberOf

	If IsEmpty(colstrGroups) Then

		Exit Sub

	End If

	If TypeName(colstrGroups) = "String" Then

		Set objGroup = GetObject("LDAP://" & colstrGroups)

		If Not objGroupList.Exists(objPriObject.sAMAccountName & "\" & objGroup.sAMAccountName) Then
			
			objGroupList(objPriObject.sAMAccountName & "\" & objGroup.sAMAccountName) = True

      			Call LoadGroups(objPriObject, objGroup)

    		End If

    		Set objGroup = Nothing

    		Exit Sub

	End If

	For j = 0 To UBound(colstrGroups)
	
		Set objGroup = GetObject("LDAP://" & colstrGroups(j))

		If Not objGroupList.Exists(objPriObject.sAMAccountName & "\" & objGroup.sAMAccountName) Then
			
			objGroupList(objPriObject.sAMAccountName & "\" & objGroup.sAMAccountName) = True

     			Call LoadGroups(objPriObject, objGroup)

   		End If
  	Next

	Set objGroup = Nothing

End Sub


function isHostOnline(address)

	on error resume next

  	dim wshShell
	dim fileSys
	dim tempFolder
	dim tempFilePath
	dim resultFile
	dim results

	' Create Objects
  	Set wshShell = CreateObject("WScript.Shell") 
  	Set fileSys = CreateObject("Scripting.FileSystemObject") 

  	tempFolder = wshShell.ExpandEnvironmentStrings("%TEMP%") 
  	tempFilePath = tempFolder & "\runresult.tmp" 

  	wshShell.Run "%comspec% /c ping.exe -n 2 -w 1000 " & address & ">" & tempFilePath, 0 , True 

  	set resultFile = fileSys.OpenTextFile(tempFilePath, 1, 0, 0) 

  	results = resultFile.ReadAll 

	resultFile.Close 
  	fileSys.DeleteFile(tempFilePath) 
  
	select case inStr(results,"TTL=") 

    		Case 0 isHostOnline = False 
    		Case Else isHostOnline = True
 
  	end select

	set wshShell = nothing
	set fileSys = nothing

end function

function serverNameFromUNC(uncPath)

	on error resume next

	' Declare variables
	dim UNCPathArray

	UNCPathArray = split(uncPath, "\")
	serverNameFromUNC = UNCPathArray(2)

end function

Open in new window

Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Any particular reason for interplay.* rather than interplay.lnk?

Chris
Avatar of IT Department

ASKER

As written above:
I have tried putting in interplan.url with no joy, tried .* no joy,

It doesn't matter if I write interplan.url or interplan.* it does the same thing... nothing.
Strictly speaking I use kill ... but it should be much the same and I have used the following to quickly test add and delete of a shortcut on the desktop to a url.

Sub addURL()

    Set WshShell = CreateObject("WScript.Shell")
    strDesktopPath = WshShell.SpecialFolders("Desktop")
    Set objShortcutUrl = WshShell.CreateShortcut(strDesktopPath & "\giggle.url")
    objShortcutUrl.TargetPath = "http://www.google.com.au"
    objShortcutUrl.Save

End Sub

Sub killURL()

    Set WshShell = CreateObject("WScript.Shell")
    strDesktopPath = WshShell.SpecialFolders("Desktop")
    Kill strDesktopPath & "\giggle.url"

End Sub

Open in new window


It will help if you can explain what it is I am not understanding?

Chris
Thanks Chris,

I am unsure I now understand you, I have the entire script there, I am trying to delete a shortcut, I have tried using a wildcard and the .url extension, both yield the same result, being that it doesn't delete the file.

Also I have copied your code and created a test.vbs file, the shortcut was not created or deleted. Could this possibly be a setting not permitting this on my machine? I have UAC off etc..

Cheers
Didn't actually double check ina script so kill isn't available but I have double checked with the key code from your script and it works fine ... Can users of the script delete the same file manually?

Chris
Hi Chris,

Our users have local admin rights at present and they can delete this file manually, yes.
It is next to impossible for anyone here to work with your script due to the system specifics therein.

Can you try a simple script like for example that I posted that calls the kill sub and see if it works stand alone?

Chris
I did Chris and I mentioned this in my post ID: ID: 38290342

Also I have copied your code and created a test.vbs file, the shortcut was not created or deleted. Could this possibly be a setting not permitting this on my machine? I have UAC off etc..

I am logged in as a domain admin and the script didn't do anything.
Can you cut your script down to the basic create and delete URL and see if it works ... And if not upload it so we can see the issue without confusion from your system setup, (servers, printers etc)

Chris
ASKER CERTIFIED SOLUTION
Avatar of IT Department
IT Department
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Chris led me in the right direction but after a few days of not looking at the script, it dawned on me that there was an if statement listed.