Jump to content

Recommended Posts

Posted

Hi there...

 

seem to be having some problems with this.. can somone look it over and tell me where im going wrong??

 

Dim compname As String

 

compname = Environment.MachineName

 

If compname = "laptop1" Or "laptop2" Or "laptop3" Then

MsgBox("YAY!!! IT WORKED!")

Else

MsgBox("BOLLOX")

 

End If

 

 

 

what i need todo is make a startup script that copys some files from a mapped network drive down to somones all users folder if there computer name match's..

 

id love to beable to put the computer name in some array, but thats even harder for me to get my head around!!

 

also. while iv got a post open.. is there any(easy) way of getting and doing this through AD groups instead of computer names?

 

so if the person logging on is in the "BLAH BLAH" group, it copys the folder down to the all users folder?

 

hope you can help!

 

thanks in advance!

 

Tom

Posted (edited)

A couple of things that may need changing if it is a VBS script.

 

VBS it typeless so it should just be

Dim compname

as the variable will remain typeless untill data is put into it.

 

You may also need to add brackets around your conditional

If (compname = "laptop1" Or "laptop2" Or "laptop3") Then

 

I think that the conditional may also need to evaluate each individually ie:

 

If (compname = "laptop1" Or compname =  "laptop2" Or compname =  "laptop3") Then

 

This may also be a quicker way of resolving the hostname:

 

Set WshNetwork = WScript.CreateObject("WScript.Network")
compname =  WshNetwork.ComputerName 

 

Not 100% sure about the speed but this is the way that I have always done it.

 

There is also WshNetwork.UserName and WshNetwork.UserDomain which will let you get the username and domain while your at it.

Edited by SYNACK
concaticated posts
Posted (edited)

Just re-read the post and there is an easy way to do it via groups:

 

Function IsMember(sGroup)
Dim sAdsPath, oUser, oGroup

If IsEmpty(oGroupDict) Then
	Set oGroupDict         = CreateObject("Scripting.Dictionary")
	oGroupDict.CompareMode = vbTextCompare

	sAdsPath  = WshNetwork.UserDomain & "/" & WshNetwork.UserName
	Set oUser = GetObject("WinNT://" & sAdsPath & ",user")

	For Each oGroup In oUser.Groups
		oGroupDict.Add oGroup.Name, "-"
	Next
	Set oUser = Nothing
End If
IsMember = CBool(oGroupDict.Exists(sGroup))
'if (IsMember) then 
'	inputFile.WriteLine(Now() & ": Success: User is member of " & sGroup)
'end if

End Function

 

usage is just:

 

if ismember("Office") then 

 

I can't take credit for this I got it of a site of system admin scripts by this guy:

 

'~~[author]~~

'Johan Greefkes

'~~[/author]~~

 

'~~[emailAddress]~~

'[email protected]

'~~[/emailAddress]~~

 

Can't remember the site now though. It might also be worth looking in the WIKI here as I think that most of this stuff is covered under the scripting section.

Edited by SYNACK
Posted

in the end, i bit the bullet, and just used autoIT.. what iv never used before. and have now coded quite a nice script!!

 

think im going to be using autoIT for most of my jobs now,

 

who else uses autoIT?

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...