Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a package

Status
Not open for further replies.

thefourthwall

IS-IT--Management
Feb 26, 2002
387
US
Hello,

As I just don't know which forum is the most appropriate for this post, suggestions are welcome.

I have been asked to take three vbscript files and some supporting files (netdom, setacl, etc.) and turn them into an .exe file that, when opened, will cause one specific vbscript file to start first.

WinZIP will package files into a self-extractor, but seems not designed to do the latter part, launching a specific file from the group of files.

I posted this originally in the WinXP forum, having forgotten about this one.

Thank you,
-thefourthwall
 
You can package a vbscript and supporting files into an EXE using PrimalScript Professional and Enterprise Edition. Both have a 45 day trial of the software.

WinRAR also lets you create a self-extracting package and you can provide a cmd line to execute. You might have the cmd line execute a single VBS that then executes your other VBS files and exe files as needed.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Thank you dm4ever. I was about to download PrimalScript when I discovered that someone here bought Installshield's packag4the web product, and i just ran the first test.

The executable runs properly, but he problem now appears to be poorly-written vbscript files (they were written by someone no longer here) which don't do what they are supposed to do.

Are you willing to take a look at the script and give me feedback?

-thefourthwall
 
Post what you have along with a detailed description of what it is supposed to do and any issues/errors you're currently experiencing with it. There a plenty of knowledgeable members here who will be able to provide feedback.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
thank you. first, a brief description: there are 4 .vbs files. the first one renames a profile folder and then starts a script to reconfigure the Novell client, then starts another script to join our domain.

that script joins the pc to the domain with no worries, but where it falls down is writing a key into the default user's registry hive to launch the last vbscript, which is copied to %windir%, (or sometimes not copied), and sometimes the last script is executed on reboot, but not always . . .sigh

the 4 scripts are (in the order executed):
-renameGenericProfile.vbe
setNovellClientSettings.vbe
-JoinOMHDomain.vbe
-CheckProfilePath.vbe

following is the code for each:

Thanks for any help you can provide.
renameGenericProfile.vbe
Code:
genericID = "sbuser"
Verbose = False

'Options:
'	genericID - generic profile to be replaced by user ID

'	verbose – True/False. If set to true, debugging popup messages will be displayed as the script runs.


'**Start Encode**
on error resume next

'Initialize Vars
novellID = ""
set objShell = CreateObject("Wscript.Shell")
const HKEY_LOCAL_MACHINE = &H80000002 'Used for WMI Reg Provider
dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
workingDirectory = replace(WScript.ScriptFullName,WScript.ScriptName,"")
if verbose then msgbox "The working directory is: " & vbcrlf & workingdirectory
'*************************************************************************
strNovellDefaultLogin = "HKEY_LOCAL_MACHINE\SOFTWARE\Novell\Location Profiles\Services\{1E6CEEA1-FB73-11CF-BD76-00001B27DA23}\Default\UserName"

'Read userID from registry
novellID = objShell.regread(strNovellDefaultLogin)
'novellID = "test"
if verbose then msgbox "Generic Id is: " & genericID & vbcrlf & "Novell ID is: " & novellID

'Check to make sure a profile with this name does not already exist, if not rename folder

on error resume next
	'read profiles paths from reg
	strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\ProfileList"
	strProfilesDir = objShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\ProfilesDirectory")
	strProfilesDir = replace(strProfilesDir,"%SystemDrive%",objShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%"))
	strGenericPath = strProfilesDir & "\" & genericID
	strDesiredPath = strProfilesDir & "\" & novellID
	if verbose then	msgbox "Generic Path is:  " & strGenericPath & vbcrlf & "Desired Path is:  " & strDesiredPath
	If filesys.FolderExists(strDesiredPath & "\") Then
		if verbose then msgbox "A profile directory with the desired name exists already!"
	else
		if verbose then msgbox "No profile directory exists with this name." & vbcrlf & "Renameing folder from " & genericID & " to " & novellID & " now."
		filesys.MoveFolder strGenericPath, strDesiredPath
	end if
	
	'kick off change novell client settings script from current directory
	Set WSHShell = CreateObject("WScript.Shell")
	WSHShell.Run "wscript """ & workingDirectory & """\setNovellClientSettings.vbe", , False	
	'kick off normal join domain script from current directory
	'Set WSHShell = CreateObject("WScript.Shell")
	WSHShell.Run "wscript """ & workingDirectory & """\JoinOMHDomain.vbe", , False


setNovellClientSettings.vbe
Code:
'ChangeNovellClientSettings

Dim WSHShell, RegKey, WorkstationOnly, RegKey2

Set WSHShell = CreateObject("WScript.Shell")

RegKey = "HKLM\Software\Novell\Login\"

RegKey2 = "HKLM\Software\Novell\Login\TAB SETTINGS\NT Credentials\"

WorkstationOnly = WSHShell.RegRead (Regkey & "Default WS Only")

WSHShell.RegWrite regkey & "Default WS Only", 0, "REG_DWORD"

WSHShell.RegWrite regkey & "Remember WS Only", 0, "REG_DWORD"

WSHShell.RegWrite regkey2 & "Sync NDS Username", 1, "REG_DWORD"


JoinOMHDomain.vbe
Code:
FacCode = "SB"
FacOU = "OU=Workstations,OU=Computers,OU=SBPC,DC=omh,DC=omhnet,DC=dom"
LogOnToDomain = True
MigrateProfiles = True
AddUserAdminGroup = True
AddPowerUsersGroup = True
Verbose = False

'v 1.9.1
'Active Directory Migration Script Written by xxxxxxxxx zxxxxxxxxxxx
'Requirements Windows 2000 or higher
'	Windows 2000 - netdom.exe, setacl.exe, reg.exe, user2sid.exe
'	Windows XP - netdom.exe, setacl.exe, user2sid.exe
'	Download at ftp://ts.omh.state.ny.us/pcdownload/AD

'Options:
'	facCode – 2 letter facility code prefix used to rename computers.

'	facOU – Active Directory OU in which to place the computer account.

'	logOnToDomain – True/False – Specifies whether the default logon should be to AD or to the local computer.

'	MigrateProfiles – True/False – Specifies whether the local profiles should be shared with an AD user who 
'					has the same username. Local Administrators and Power Users groups will also be checked. 
'					Any users will be matched with AD users.

'   AddUserAdminGroup - Adds a domain group to the local PC Administrators group in the form XXAdminUsers
'                    where XX is the Facility Code. Used to manage PC Admin users without visiting desktops.

'   AddPowerUsersGroup - Adds a domain group to the local PC PowerrUsers group in the form XXPowerUsers
'                    where XX is the Facility Code. Used to manage PC Power Users users without visiting desktops.
'

'	verbose – True/False. If set to true, debugging popup messages will be displayed as the script runs.


'**Start Encode**
on error resume next

'Initialize Vars
omhUser = "omh\istsomh"
omhPwd = "8*0k99$#vBHy-1!xxMqOP"
rebootMe = False
rebootReason = ""
SDMCacheDir = replace(WScript.ScriptFullName,WScript.ScriptName,"")'Find the current script location or SDMCache directory for RunOnce and uilility file Usage
const HKEY_LOCAL_MACHINE = &H80000002 'Used for WMI Reg Provider
set objShell = CreateObject("Wscript.Shell")
set objNet = CreateObject("Wscript.Network")
set objFSO = CreateObject("Scripting.FileSystemObject")

'Do some work
if PingStatus("omh.omhnet.dom") then
	if verbose then msgbox "Ping Status Good for omh.omhnet.dom",,"Join OMH Domain"

		if getRole = "Member" then
			addAdmins
			addPowerUsers
			if migrateProfiles then shareProfiles
			SetDNSSuffix
			joinDomain
			CheckComputerName ' Rename and set default logon to OMH Domain or new computername per logOnToDomain value
			checkReboot
		end if
	
			if getRole = "Standalone" then
			SetDNSSuffix
			joinDomain
			CheckComputerName ' Rename and set default logon to OMH Domain or new computername per logOnToDomain value
			addAdmins
			addPowerUsers
			if migrateProfiles then shareProfiles
			checkReboot
		end if

else
	if verbose then msgbox "There is a Network or DNS problem on this computer. Can't join the OMH domain. Please contact the HelpDesk.",,"Join OMH Domain - Error" 
end if
'clean up
set objShell = nothing
set objNet = nothing
set objFSO = nothing

'*********************************************************************

'Check for FacCode Prefix
Sub CheckComputerName()
	'If the computer Name does not start with the Facility Prefix then rename it
	if left(objNet.ComputerName,2) <> facCode then
		if verbose then msgbox "Computer Name does not start with " & faccode & "." & vbcrlf & "Need to Rename Computer",,"Check ComputerName"
		RenameComputer()
		'update default logon domain to new computer name or domain if specified in logOnToDomain
		setDefaultDomain faccode & objnet.ComputerName
	
	
	elseif LocalUserExists(left(objNet.ComputerName,7)) then
			if verbose then msgbox "The Computer Name matches the facility code prefix but appears to start with a UserID." & vbcrlf & "The computer needs to be renamed",,"Check ComputerName - Local User"
			RenameComputer()
			'update default logon domain to new computer name or domain if specified in logOnToDomain
			setDefaultDomain faccode & objnet.ComputerName
	
	
	elseif ADUserExists(left(objNet.ComputerName,7)) then
			if verbose then msgbox "The Computer Name matches the facility code prefix but appears to start with a UserID." & vbcrlf & "The computer needs to be renamed",,"Check ComputerName - AD User"
			RenameComputer()
			'update default logon domain to new computer name or domain if specified in logOnToDomain
			setDefaultDomain faccode & objnet.ComputerName
	else
			if verbose then msgbox "The Computer Name matches the facility code prefix and does NOT appear to start with a UserID." & vbcrlf & "The computer does NOT need to be renamed",,"Check ComputerName"
			'set default logon to domain if specified in logOnToDomain
			setDefaultDomain objnet.ComputerName
		
	end if
end Sub

Sub RenameComputer()
	'Check new length for greater than 15 Characters
	if len(facCode & objNet.ComputerName) > 15 then
		if verbose then msgbox "New Computer Name is greater than 15 Characters! LANDesk and NETBIOS may have issues.",,"Rename Computer"
	end if
	if left(objNet.ComputerName,3) = "EPC" then
		newComputerName =  replace(objnet.ComputerName,"EPC",faccode)
	else
		newComputerName = facCode & objnet.ComputerName
	end if
		
	strCMD = """" & SDMCacheDir & "netdom.exe"" renamecomputer " & objNet.ComputerName & " /NewName:" & newComputerName & " /UserD:"& omhuser & " /PasswordD:" & omhPwd & " /Force"
	if verbose then msgbox "Renaming Computer" & vbcrlf & replace(strCMD,omhPwd,"xxxxxxxx")
	objShell.Run strCMD,0,True
	rebootMe = True
	rebootReason = rebootReason & vbcrlf & "Computer Name Changed"
	
end Sub


Sub joinDomain()
	if getrole = "Member" and getdomain = "OMH" then		
		if verbose then msgbox "This computer is already a member of the OMH domain." & vbcrlf & "It does NOT need to be joined to the domain.",,"Join Domain"
	else
		if getrole = "Member" then 
			if verbose then msgbox "This computer is currently a member of the " & getDomain & " domain." & vbcrlf & "It needs to be removed from this domain.",,"Join Domain"
			strCMD = """" & SDMCacheDir & "netdom.exe"" remove " & objNet.ComputerName
			if verbose then msgbox strCMD
			objShell.Run strCMD,0,True
		end if
		if verbose then msgbox "This computer is currently a member of the " & getDomain & " workgroup." & vbcrlf & "It needs to be joined to the OMH domain.",,"Join Domain"
		strCMD = """" & SDMCacheDir & "netdom.exe"" join " & objNet.ComputerName & " /Domain:omh.omhnet.dom /OU:" & facOU & " /UserD:"& omhuser & " /PasswordD:" & omhPwd
		if verbose then msgbox replace(strCMD,omhPwd,"xxxxxxxx")
		objShell.Run strCMD,0,True
		rebootMe = True
		rebootReason = rebootReason & vbcrlf & "Domain Membership Changed"	
	end if
end Sub

Sub setDefaultDomain(byVal domainName)
	on error resume next
	if logOnToDomain then domainName = "OMH"
    err.Clear
	strMicrosoftDefaultDomainName = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultDomainName"
	'Check for Microsoft Client
	objShell.regread(strMicrosoftDefaultDomainName)
	if err.number = 0 then
		if verbose then msgbox "Setting Microsoft Client Default Logon Domain to " & domainName
		objShell.RegWrite strMicrosoftDefaultDomainName,domainName,"REG_SZ"
	end if
	err.Clear 
	strNovellDefaultDomainName = "HKEY_LOCAL_MACHINE\SOFTWARE\Novell\Location Profiles\Services\{1E6CEEA1-FB73-11CF-BD76-00001B27DA23}\Default\Tab3\DefaultDomainName"
	'Check for Novell Client
	objShell.regread(strNovellDefaultDomainName)
	if err.number = 0 then
		if verbose then msgbox "Setting Novell Client Default Logon Domain to " & domainName
		objShell.RegWrite strNovellDefaultDomainName,domainName,"REG_SZ"
	end if
end Sub

Sub addAdmins()
	on error resume next
	if verbose then msgbox "Querying Local Administrators Group and Adding Domain Accounts to Match",,"Add Admins"
	Set objGroup = GetObject("WinNT://" & objNet.Computername & "/Administrators,group")
	'Add a domain user for each local user
	For each objUser in objGroup.Members
		if adUserExists(objuser.Name) then
			if verbose then msgbox "Adding OMH\" & objuser.name & " to the Administrators Group",,"Add Admins"
			objGroup.Add( "WinNT://OMH/" & objuser.Name & ",user" )
		else 
			if verbose then msgbox "User: " & objuser.Name & " does not exist in AD",,"Add Admins"
		end if
	next
	'Add WSS and Local Facility Admins to the Local Administrators group
	if verbose then msgbox "Adding Local Admin Groups..." & vbcrlf & "OMH\WSS" & vbcrlf & "OMH\" & facCode & "Admins",,"Add Admins"
	objGroup.Add( "WinNT://OMH/WSS,group" )
	objGroup.Add( "WinNT://OMH/" & facCode & "Admins,group" )
	if AddUserAdminGroup then
		if verbose then msgbox "Adding Local Admin Group for Admin users..." & vbcrlf & "OMH\" & facCode & "AdminUsers",,"Add Admins"
		objGroup.Add( "WinNT://OMH/" & facCode & "AdminUsers,group" )
	end if
	set objgroup = nothing
end Sub

Sub addPowerUsers()
	on error resume next
	if verbose then msgbox "Querying Local Power Users and Adding Domain Accounts to Match",,"Add Power Users"
	Set objGroup = GetObject("WinNT://" & objNet.Computername & "/Power Users,group")
	'Add a domain user for each local user
	For each objUser in objGroup.Members
		if adUserExists(objuser.Name) then
			if verbose then msgbox "Adding OMH\" & objuser.name & " to the Power Users Group",,"Add Power Users"
			objGroup.Add( "WinNT://OMH/" & objuser.Name & ",user" )
		else 
			if verbose then msgbox "User: " & objuser.Name & " does not exist in AD",,"Add Power Users"
		end if
	next
	'Add PowerUsers Domain Group
	if AddPowerUsersGroup then
		if verbose then msgbox "Adding Domain PowerUsers Group..." & vbcrlf & "OMH\" & facCode & "PowerUsers",,"Add PowerUsers"
		objGroup.Add( "WinNT://OMH/" & facCode & "PowerUsers,group" )
	end if
	set objgroup = nothing
end Sub

Sub shareProfiles()
	on error resume next
	'read profiles paths from reg
	strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\ProfileList"
	strProfilesDir = objShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\ProfilesDirectory")
	set profilesPath = objFSO.GetFolder(replace(strProfilesDir,"%SystemDrive%",objShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")))
	for each userProfile in profilesPath.Subfolders
	'check for default path "docs and settings\userid" - Skip those that are not default
	'if there is a . in the profile path then it's not default
	if instr(1,userProfile,".",1) = 0 then 
		'Open Profiles list in reg
		strComputer = "."
		Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"& strComputer & "\root\default:StdRegProv")
		'Enumerate Profiles in Registry
		objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
		'Match SID regkey to actual profile path
		For Each sid In arrSubKeys
			'Read the ProfileImagePath for the Registry
			regProfilePath = objShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\" & sid & "\" & "ProfileImagePath")
				'Match the Reg Path to the File Path
				if userProfile = replace(regProfilePath,"%SystemDrive%",objShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")) then
					myUser = replace(userProfile,profilesPath & "\","")
					if verbose then msgbox "Querying AD for user OMH\" & myUser,,"Share Profiles"
					if AdUserExists(myUser) then
						OMHSid = userSid(myUser)
						if verbose then msgbox "Setting Permissions to Share Profile " & vbcrlf & sid & vbcrlf & userprofile & vbcrlf & " with OMH\" & myUser & " : " & OMHSid,,"Share Profiles"
					
						'Set File Permissions
						strCMD = """" & SDMCacheDir & "SetACL.exe"" -on """ & userProfile & """ -ot file -actn ace -ace ""n:" & OMHSid & ";p:full;s:y"" -op ""dacl:p_nc;sacl:p_nc"""
						if verbose then msgbox "Setting File Permissions for OMH\" & myUser & vbcrlf & strCMD,,"Share Profles"
						objShell.Run strCMD,0,True
						
						'Set Protection
						strCMD = """" & SDMCacheDir & "SetACL.exe"" -on """ & userProfile & """ -ot file -actn setprot -op ""dacl:p_nc;sacl:p_nc"""
						if verbose then msgbox "Setting File Protection for OMH\" & myUser & vbcrlf & strCMD,,"Share Profles"
						objShell.Run strCMD,0,True
					
						'attempt to load CU hive incase user is not logged on
						strCMD = """" & SDMCacheDir & "reg.exe"" load ""HKU\" & sid & """ """ & userprofile & "\ntuser.dat"""
						if verbose then msgbox "Loading Registry Hive for user OMH\" & myUser & vbcrlf & strCMD,,"Share Profiles"
						objShell.Run strCMD,0,True
					
						'attempt to load UserClasses hive incase user is not logged on
						strCMD = """" & SDMCacheDir & "reg.exe"" load ""HKU\" & sid & "_Classes" & """ """ & userprofile & "\Local Settings\Application Data\Microsoft\Windows\UsrClass.dat"""
						if verbose then msgbox "Loading UserClasses Registry Hive for user OMH\" & myUser & vbcrlf & strCMD,,"Share Profiles"
						objShell.Run strCMD,0,True
						
						'attempt to set perms for CU reg hive
						strCMD = """" & SDMCacheDir & "SetACL.exe"" -on ""hku\" & sid & """ -ot reg -actn ace -ace ""n:" & OMHSid & ";p:full;s:y"" -op ""dacl:nc;sacl:nc"""
						if verbose then msgbox "Setting CU Registry Permissions for user OMH\" & myUser & vbcrlf & strCMD,,"Share Profiles"
						objShell.Run strCMD,0,True
					
						'attempt to set perms for CU Policies Key 1
						strCMD = """" & SDMCacheDir & "SetACL.exe"" -on ""hku\" & sid & "\software\policies" & """ -ot reg -actn ace -ace ""n:" & OMHSid & ";p:read;s:y"" -rec yes -op ""dacl:p_nc;sacl:p_nc"""
						if verbose then msgbox "Setting CU Registry Permissions for user OMH\" & myUser & vbcrlf & strCMD,,"Share Profiles"
						objShell.Run strCMD,0,True
								
						'attempt to set perms for CU Policies Key 2
						strCMD = """" & SDMCacheDir & "SetACL.exe"" -on ""hku\" & sid & "\software\microsoft\windows\current version\policies" & """ -ot reg -actn ace -ace ""n:" & OMHSid & ";p:read;s:y"" -rec yes -op ""dacl:p_nc;sacl:p_nc"""
						if verbose then msgbox "Setting CU Registry Permissions for user OMH\" & myUser & vbcrlf & strCMD,,"Share Profiles"
						objShell.Run strCMD,0,True
					
						'attempt to set perms for UserClasses reg hive
						strCMD = """" & SDMCacheDir & "SetACL.exe"" -on ""hku\" & sid & "_Classes" & """ -ot reg -actn ace -ace ""n:" & OMHSid & ";p:full;s:y"" -op ""dacl:nc;sacl:nc"""
						if verbose then msgbox "Setting UserClasses Registry Permissions for user OMH\" & myUser & vbcrlf & strCMD,,"Share Profiles"
						objShell.Run strCMD,0,True
					
						'attempt to unload CU hive
						strCMD = """" & SDMCacheDir & "reg.exe"" unload ""HKU\" & sid & """"
						if verbose then msgbox "Unloading Registry Hive for user OMH\" & myUser & vbcrlf & strCMD,,"Share Profiles"
						objShell.Run strCMD,0,True
						
						'attempt to unload UserClasses hive
						strCMD = """" & SDMCacheDir & "reg.exe"" unload ""HKU\" & sid & "_Classes" & """"
						if verbose then msgbox "Unloading Registry Hive for user OMH\" & myUser & vbcrlf & strCMD,,"Share Profiles"
						objShell.Run strCMD,0,True
					else
						if verbose then msgbox "User: OMH\" & myUser & " Does not exist in AD",,"Share Profiles"
					end if
				end if
		Next		
	else
		if verbose then msgbox "User Profile Skipped (not in default location)" & vbcrlf & userprofile
	end if		
	Next
	'Load Default User Profile
	strCMD = """" & SDMCacheDir & "reg.exe"" load ""HKU\DEFAULTUSER"" """ & strProfilesDir & "\Default User\ntuser.dat"""
	if verbose then msgbox "Loading Registry Hive for Default User" & vbcrlf & strCMD,,"Share Profiles"
	objShell.Run strCMD,0,True

	'Add Profile Path checker to RunOnce Key for Default User and copy to Windows folder.
	windir= objshell.ExpandEnvironmentStrings("%SYSTEMROOT%")
	objfso.CopyFile sdmcachedir & "CheckProfilePath.vbe",windir & "\CheckProfilePath.vbe"
	if verbose then msgbox "Adding Profile Path Checker to RunOnce Key for Default User",,"Share Profiles"
	strRegRun = "HKEY_USERS\DEFAULTUSER\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\ProfilePathChecker"
	objShell.RegWrite strRegRun,"wscript.exe " & windir & "\CheckProfilePath.vbe","REG_SZ"
	
	'UnLoad Default User Profile
	strCMD = """" & SDMCacheDir & "reg.exe"" unload ""HKU\DEFAULTUSER"""
	if verbose then msgbox "Unoading Registry Hive for Default User" & vbcrlf & strCMD,,"Share Profiles"
	objShell.Run strCMD,0,True
	
	'Loosen Profile Paths Reg Perms for non Admin Users - This is only needed becausae some PC images had screwy reg perms
	strCMD = """" & SDMCacheDir & "SetACL.exe"" -on ""hklm\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"" -ot reg -actn ace -ace ""n:Users;p:full"" -op ""dacl:p_nc;sacl:p_nc"""
	if verbose then msgbox "Setting Registry Permissions for Profile Path Checker Script" & vbcrlf & strCMD,,"Share Profiles"
	objShell.Run strCMD,0,True
	
	'Delete Temp Files from the Default User Profile to save space
	if verbose then msgbox "Cleaning up Temp files from Default user Profile",,"Share Profiles"
	strDefaultUser = replace(strProfilesDir,"%SystemDrive%",objShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")) & "\Default User"
	objfso.DeleteFolder strDefaultUser & "\Local Settings\Temp",True
	objfso.DeleteFolder strDefaultUser & "\Local Settings\Temporary Internet Files",True
	objfso.CreateFolder strDefaultUser & "\Local Settings\Temp"
	objfso.CreateFolder strDefaultUser & "\Local Settings\Temporary Internet Files"
end Sub

Sub checkReboot()
	if rebootMe = True then
		if verbose then 
			prompt = msgbox("The Computer Must be rebooted because " & rebootReason & vbcrlf & "Click Yes to Reboot Now.",vbyesno,"Reboot")
			if prompt = 6 then Reboot
			exit sub
		end if
		Reboot
	else
	if verbose then msgbox "The computer does not need a reboot"
	end if
	
end Sub

Sub Reboot()
	nLogOff=0
	nReboot=2
	nForceLogOff=4
	nForceReboot=6
	nPowerDown=8
	nForcePowerDown=12
	Set oOS = GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from Win32_OperatingSystem")
	For Each oOperatingSystem in oOS
	oOperatingSystem.Win32Shutdown(nForceReboot)
	Next
End sub



Function AdUserExists(byval strUserName)
	Set objConnection = CreateObject("ADODB.Connection")
	objConnection.Open "Provider=ADsDSOObject;", omhUser, omhPwd
	Set objCommand = CreateObject("ADODB.Command")
	objCommand.ActiveConnection = objConnection 
	objCommand.CommandText = "<LDAP://omh.omhnet.dom/dc=omh,dc=omhnet,dc=dom>;(&(objectCategory=User)(samAccountName=" & strUserName & "));samAccountName;subtree" 
	Set objRecordSet = objCommand.Execute
	AdUserExists = cbool(objRecordset.RecordCount)
	objConnection.Close
end Function

Function LocalUserExists(byval strUser)	
	on error resume next
	if verbose then msgbox "Checking for Local User Account for " & strUser,,"Local User Exists"
	err.clear
	Set objUser = GetObject("WinNT://" & objNet.ComputerName & "/" & strUser & ",user")
	if err.number = 0 then 
		LocalUserExists = True
	else 
		LocalUserExists = False
		err.clear
	end if
	set objUser = nothing
End Function

function UserSid(byval strUserName)
	strCMD = "cmd /c """ & SDMCacheDir & "user2sid.exe"" OMH\" & strUserName & ">" & strUserName & ".sid"
	'if verbose then msgbox strCMD,,"Get User SID"
	objShell.Run strCMD,0,True
	set myfile = objfso.OpenTextFile(strUserName & ".sid")
	myfile.readline ' first line is blank
	userSid = myfile.readline
end function

Function getDomain()
	Set colComputer = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("SELECT Domain FROM Win32_ComputerSystem")
	For Each objComputer in colComputer
		if objComputer.Domain = "OMH" or objComputer.Domain = "omh.omhnet.dom" then 
			getDomain = "OMH"
		else
			getDomain = objComputer.Domain
		end if
	Next
End Function

Function getRole()
	Set colComputer = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("SELECT DomainRole FROM Win32_ComputerSystem")
	For Each objComputer in colComputer
    	Select Case objComputer.DomainRole 
        	Case 0 
            		getRole = "Standalone" ' Workstation
        	Case 1        
            		getRole = "Member" ' Workstation
        	Case 2
            		getRole = "Standalone" ' Server
        	Case 3
            		getRole = "Member" ' Server
        	Case 4
            		getRole = "Backup Domain Controller"
        	Case 5
            		getRole = "Primary Domain Controller"
    	End Select

	Next
End Function


function PingStatus(byval strDNS)
	Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
	Set colItems = objWMIService.ExecQuery _
	    ("Select * from Win32_PingStatus Where Address = '" & strDNS & "'")

	For Each objItem in colItems
		if objItem.Statuscode = 0 then 
			PingStatus = True
		else
			PingStatus = False
		end if
	Next
	set objWMIService = nothing
End Function

Sub SetDNSSuffix()
	'Set the computer name DNS Suffix to Change as domain membership changes.
	if verbose then msgbox "Setting computer DNS suffix to Sync with Domain Membership Change",,"DNS Suffix"
	objshell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\SyncDomainWithMembership", 1, "REG_DWORD"
	objshell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Domain", "omh.omhnet.dom", "REG_SZ"
		
end Sub

CheckProfilePath.vbe
Code:
Verbose = False
'v 1.3
'Check the user profile path for a non default path (eg. userid.000) and prompts the user to optionally transfer old settings.
'If the user chooses yes then then path is changed back to the default path.

'**Start Encode**

on error resume next

const HKEY_LOCAL_MACHINE = &H80000002
const HKEY_USERS = &H80000003
set objShell = CreateObject("Wscript.Shell")
newpath = array()

checkProfiles

set objreg = nothing
set objshell = nothing


sub checkProfiles()
	userProfile = objShell.ExpandEnvironmentStrings("%USERPROFILE%")
	'check for default path "docs and settings\userid" - Skip those that are not default
	'if there is a . in the profile path then it's not default
	if instr(1,userProfile,".",1) = 0 then 
		if verbose then msgbox "Your Profile Path is good."
	else
		strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\ProfileList"
		'Open Profiles list in reg
		strComputer = "."
		Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"& strComputer & "\root\default:StdRegProv")
		'Enumerate Profiles in Registry
		objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
		'Match SID regkey to actual profile path and fix it
		For Each sid In arrSubKeys
			regProfilePath = objShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\" & sid & "\" & "ProfileImagePath")
			if replace(regProfilePath,"%SystemDrive%",objShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")) = userProfile then
					newpath = split(regProfilePath,".")
					prompt = msgbox("The Active Directory Upgrade is complete." & vbcrlf & "Would you like your Desktop Shortcuts and Internet Favorites from before the upgrade?(Reboot Required)",vbyesno, "Upgrade Complete. Transfer Settings?")
					if prompt = 6 then
						if verbose then msgbox regProfilePath & " needs fixin." & vbcrlf & "Setting profile path to  " & newpath(0)
						objshell.RegWrite "HKEY_LOCAL_MACHINE\" & strKeyPath & "\" & sid & "\" & "ProfileImagePath", newPath(0), "REG_EXPAND_SZ"	
						if verbose then msgbox "You need to reboot for the new settings to take affect."
						logoff
					end if
			end if
		Next	
	end if				
end sub

Sub Logoff
	nLogOff=0
	nReboot=2
	nForceLogOff=4
	nForceReboot=6
	nPowerDown=8
	nForcePowerDown=12
	Set oOS = GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from Win32_OperatingSystem")
	For Each oOperatingSystem in oOS
		oOperatingSystem.Win32Shutdown(nForceReboot)
	Next

End sub




 
dm4ever,

should you get a chance to look at the above-posted code, i would be quite grateful.

thanks,
-thefourthwall
 
That's one huge script...I'll take a look as time permits...plus I'm coming down with a cold or flu so it may slow me down a bit too.

So the scripts works...just not consistently...is that the issue?

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Yes, it is a rather large script, i'd agree.

Correct -- most of it works all the time, and parts of it fail sometimes.

A brief summary:
1. renameGenericProfile.vbe gets the last-known Novell username and renames the generic local user profile to the Novell name. It then starts a 2nd script to modify the Novell client settings, and then starts a 3rd script to join the pc to a domain.
2. that 3rd script, joinohmdomain.vbe, joins the pc to a domain and then is supposed to a) add a runonce key to the Default User's registry hive by loading the hive using reg.exe and then unloading it, and b) copy the file referenced in the runonce key to the %windir% directory for processing after restart.

It is those two above steps, a) and b) that fail; either the key is not written to the registry or the file is not copied to %windir% or sometimes both of those things do not happen. Sigh . . .
 
I see the JoinOMHDomain.vbe has an option at the top Verbose = False

Have you tried setting it to True to possibly see where it is failing? You might also consider commenting the on error resume next to see any errors on the machines that this is not working properly on.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
it seems the problem (for the most part) was in how the scripts were being packaged into a .exe for landesk distribution.

The person doing the packaging was using InstallShield's "Package for the web" and was checking the "delete files after installation completes" option. This had the effect of deleting the files after the initial batch file launched and completed; this was causing the files needed to be deleted before the script actually completed.

whew! does that make sense? [ponder]
 
I've never packaged using InstallShield "Package for the web" so I'm not sure if that is how it was supposed to behave.

In any case, if it seems to have taken care of the majority of the issues then that's what really matters.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Indeed the majority of the issues have been taken care of, thanks for your willingness to look at the code i must work with.

i'm going to lead off in a slightly different direction, please tell me if what i'm about to write belongs in a different forum?

the scripts now all work, but one remaining problem: the pre-migrated local account has, say, a certain background set; after the migration, that background displays in the list of available backgrounds, and is selected, but does not actually display on the desktop.

if however, one opens that file with IE and then right-clicks the displayed image to select "Set as Background" the image displays as the background, the desired result all along.

any thoughts?

thanks,
-thefourthwall
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top