Americare
asked on
Login Script
I have an Active directory login script that runs on all users. I would like to put at the begining of the script, if the computer name is XXXXX, then dont run the script. I would like to use a list of computer names. How can I do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Set DoScript=True
FOR /F "tokens=1" %%I IN (a.txt) DO IF %%I==%COMPUTERNAME% SetDoScript=False
If %DoScript%==False GOTO :EOF
:MAIN
pause
:EOF
FOR /F "tokens=1" %%I IN (a.txt) DO IF %%I==%COMPUTERNAME% SetDoScript=False
If %DoScript%==False GOTO :EOF
:MAIN
pause
:EOF
ASKER
Hengtime:
If I do this:
IF %COMPUTERNAME% == "SomeComputerName" GOTO NOINSTALL
:INSTALL
And at the end of the file I put
:NOINSTALL
Will that work?
If I do this:
IF %COMPUTERNAME% == "SomeComputerName" GOTO NOINSTALL
:INSTALL
And at the end of the file I put
:NOINSTALL
Will that work?
ASKER
Blimster:
Will that work in a batch file? Can I put that at the beinging of the script?
a.txt? IS that the list of computer names I want to exclude? Where do I put that file?
Will that work in a batch file? Can I put that at the beinging of the script?
a.txt? IS that the list of computer names I want to exclude? Where do I put that file?
yess that is a batch .bat or .cmd will do
yes just put it at the start of the script and have you main script under the :MAIN label
i've put the pause in there just for light testing, so remove it when you add it.
the a.txt can be any text based file that holds whe workstations names.
ie
pc1
pc2
pc3
NOTE(BIG NOTE):
the path to a.txt must not have anyspaces, you cannot substitue this for environment varibles and you cannot put double quotes around it as the for statement interperates them differently.
yes just put it at the start of the script and have you main script under the :MAIN label
i've put the pause in there just for light testing, so remove it when you add it.
the a.txt can be any text based file that holds whe workstations names.
ie
pc1
pc2
pc3
NOTE(BIG NOTE):
the path to a.txt must not have anyspaces, you cannot substitue this for environment varibles and you cannot put double quotes around it as the for statement interperates them differently.
Here's a VBScript version if your into that. (Better imo)
similar to the batch but should handel spaces better then the batch
same as before a.txt holds the list
the last like will run your batch script if a workstation isn't in the list.
just replace login.bat with a full path to your script. It should take environment variables here.
so just make the vbs your login script and replace login.bat with the full path to your current login script
and replace a.txt with the full path to your exclusion list i
similar to the batch but should handel spaces better then the batch
same as before a.txt holds the list
the last like will run your batch script if a workstation isn't in the list.
just replace login.bat with a full path to your script. It should take environment variables here.
so just make the vbs your login script and replace login.bat with the full path to your current login script
and replace a.txt with the full path to your exclusion list i
Option Explicit
On Error Resume Next
Const ForReading = 1
Dim objShell, objFSO, objNetwork, objFIle
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
Dim index, wks, strList
Dim arrWks()
strList = "a.txt" 'replace with your list
Set objFile = objFSO.OpenTextFile(strList, ForReading)
index = 0
Do Until objFile.AtEndOfStream
ReDim Preserve arrWks(index)
arrWks(index) = objFile.ReadLine
index = index + 1
Loop
objFile.Close
For Each wks In arrWks
If objNetwork.Computername = wks then WScript.quit
Next
objShell.Run "cmd.exe /k" & "Login.bat" 'run DOS commands
you can comment out like to for trouble shooting.
but yeah much more flexible then the batch
but yeah much more flexible then the batch
IF %COMPUTERNAME% == "SomeComputerName" GOTO NOINSTALL
:INSTALL
And at the end of the file I put
:NOINSTALL
That would work!
:INSTALL
And at the end of the file I put
:NOINSTALL
That would work!
ASKER
Neither one of these solutions are working effectivley. Is there a way using IF Member and an active directory group?
you mean it isnt working at all?
what OS is running on the computers?
what OS is running on the computers?
Create a file excludedPC.txt and put it in the same folder of your batch
::excludedPC.txt saple file
pc1
pc2
pc3
myPC
then modify your batch
@echo off
setlocal
findstr /x /i "%computername%" %0\..\excludedPC.txt && goto :NoInstall
:: start of your batch
:: end of your batch
:NoInstall
::excludedPC.txt saple file
pc1
pc2
pc3
myPC
then modify your batch
@echo off
setlocal
findstr /x /i "%computername%" %0\..\excludedPC.txt && goto :NoInstall
:: start of your batch
:: end of your batch
:NoInstall
Don't see how the VBS script doesn't work. What do you mean by "effectiveley"?
You can find if the user is part of an OU with this VBS
Difference between this and the previous VBS is that this check the OU rather then the list.
More manageable.
Still executes like the previous one (ie kicks off you current script "Login.bat" or what ever it is) if the user is not apart of the excluded OU
Echo statements are for light trouble shooting remove them when your happy.
You can find if the user is part of an OU with this VBS
Difference between this and the previous VBS is that this check the OU rather then the list.
More manageable.
Still executes like the previous one (ie kicks off you current script "Login.bat" or what ever it is) if the user is not apart of the excluded OU
Echo statements are for light trouble shooting remove them when your happy.
On Error Resume Next
Dim wshNetwork, objConnection, objCommand, objRecordSet, objShell
Dim strUser, strUserOU, strExcludeOU
Const ADS_SCOPE_SUBTREE = 2
Set wshNetwork = CreateObject("WScript.Network")
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set objShell = CreateObject("WScript.Shell")
strUser = wshNetwork.Username
strUser = Trim(strUser)
strExcludeOU = "Script Off OU"
strExcludeOU = Trim(strExcludeOU)
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT distinguishedName FROM 'LDAP://dc=hic,dc=hicnet'WHERE objectCategory='user'AND sAMAccountName='" & strUser & "'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Dim strDN, arrPath, intLength, intNameLength
strDN = objRecordSet.Fields("distinguishedName").Value
arrPath = Split(strDN, ",")
intLength = Len(arrPath(1))
intNameLength = intLength - 3
strUserOU = Right(arrPath(1), intNameLength)
If strUserOU = strExcludeOU Then
WScript.Echo (strUser & " is apart of " & strExcludeOU)
WScript.Quit
End If
objRecordSet.MoveNext
Loop
WScript.Echo (strUser & " is not apart of " & strExcludeOU)
objShell.Run "cmd.exe /k" & "Login.bat" 'run DOS commands
Forgot to add.
Replace the dc=hic, dc=hicnet with your own dc.
(Duh!) but still...
Replace the dc=hic, dc=hicnet with your own dc.
(Duh!) but still...
And strExcludeOU = "Script Off OU"
with whatever your group is..
with whatever your group is..
ASKER
ALL:
These are WYSE xpe thin client computers. The users logging into them from the domain have an attached login script that needs to run for other machines they log into. But on these particular machines, the login script needs to be blocked. Do you see any other way to attack this problem?
These are WYSE xpe thin client computers. The users logging into them from the domain have an attached login script that needs to run for other machines they log into. But on these particular machines, the login script needs to be blocked. Do you see any other way to attack this problem?
Give us the output of this command on Wyse tc
wmic computersystem get model
You can run it with w normal user ?
wmic computersystem get model
You can run it with w normal user ?
Name1
Name2
Name3
and then use
findstr /X "ComputerName" "ExcludedComputers.txt"
IF ERRORLEVEL 1
<The code you want to exectue if the computer name is not found"