+ Post New Thread
Results 1 to 5 of 5
Coding Thread, Environment.MachineName in Coding and Web Development; Hi there... seem to be having some problems with this.. can somone look it over and tell me where im ...
  1. #1

    Join Date
    Feb 2008
    Location
    Stevenage, Hertfordshire
    Posts
    111
    Thank Post
    3
    Thanked 8 Times in 5 Posts
    Rep Power
    14

    Environment.MachineName

    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

  2. #2

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    10,691
    Thank Post
    824
    Thanked 2,570 Times in 2,187 Posts
    Blog Entries
    9
    Rep Power
    731
    A couple of things that may need changing if it is a VBS script.

    VBS it typeless so it should just be
    Code:
    Dim compname
    as the variable will remain typeless untill data is put into it.

    You may also need to add brackets around your conditional
    Code:
    If (compname = "laptop1" Or "laptop2" Or "laptop3") Then
    I think that the conditional may also need to evaluate each individually ie:

    Code:
    If (compname = "laptop1" Or compname =  "laptop2" Or compname =  "laptop3") Then
    This may also be a quicker way of resolving the hostname:

    Code:
    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.
    Last edited by SYNACK; 20th April 2008 at 02:35 PM. Reason: concaticated posts

  3. #3

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    10,691
    Thank Post
    824
    Thanked 2,570 Times in 2,187 Posts
    Blog Entries
    9
    Rep Power
    731
    Just re-read the post and there is an easy way to do it via groups:

    Code:
    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:

    Code:
    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]~~
    'parcival@gmail.com
    '~~[/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.
    Last edited by SYNACK; 20th April 2008 at 02:31 PM.

  4. #4

    Join Date
    Feb 2008
    Location
    Stevenage, Hertfordshire
    Posts
    111
    Thank Post
    3
    Thanked 8 Times in 5 Posts
    Rep Power
    14
    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?

  5. #5
    bizzel's Avatar
    Join Date
    Jul 2007
    Location
    Cambridge
    Posts
    654
    Thank Post
    102
    Thanked 204 Times in 72 Posts
    Rep Power
    50
    Quote Originally Posted by Tom-Kirby View Post
    who else uses autoIT?
    The Edugeek admin bar is all AutoIT, I think.

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 8
    Last Post: 10th April 2008, 01:52 PM
  2. Test Environment
    By Neville in forum Thin Client and Virtual Machines
    Replies: 2
    Last Post: 25th February 2008, 10:19 AM
  3. Learning Environment Manager
    By DanLW in forum Educational IT Jobs
    Replies: 1
    Last Post: 20th February 2008, 11:04 AM
  4. Environment variables or other method
    By HodgeHi in forum Scripts
    Replies: 3
    Last Post: 21st June 2006, 09:05 AM
  5. Study environment
    By dezt in forum How do you do....it?
    Replies: 16
    Last Post: 10th March 2006, 09:58 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •