Help with fairly complex login script

Would like someone to design a script for the environment I manage that does a number of things. These items must take place in numerical order. May be a .bat file however, .vbs, .cmd  and .ps1 are acceptible.
The script needs to be able to do the following:
1. run at logon via AD GPO.
2. immediately sleep for 10 seconds.
3. determine day of week:
 * on specified day of week displays pop up message.
 * on day message displayed, message must be visible for minimum 5 seconds.
 * message can contain an "OK" button to confirm.
4. script must contain a section that does the following:
 * ping an IP address
 * if ping unsuccesful, ping again.
 * if ping successful, continue script.
5. Script must run IPCONFIG /REGISTERDNS
6. script must map multiple drives.
 * F:, P:, S:, and V:
 * group membership determines drive mapping.
 * Share path varies with group membership.
7. script must copy several files from one of the mapped drives to a location on the hard disk.
 * copy F:\txt1\1.txt C:\folder1
 * copy F:\txt1\2.txt C:\folder1
 * copy F:\txt2\3.txt C:\folder2
LVL 7
iedenAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BillBondoCommented:
kixtart, simple and I believe free
yelbaglfCommented:
What does your existing script look like?  Is it something that you could share, so that we have a starting point moving forward?  

Example variables that you can use.
 
Dim objFSO
Dim fServer
Dim pServer
Dim objNetwork
Dim objWinntUser

Const strSG1 = "Billing"
Const strSG2 = "HR"

Open in new window


Put me to sleep for 10 seconds.
 
WScript.Sleep 10000

Open in new window


Day of Week
simple case statement
 
dtmToday = Date()
dtmDOW = DatePart("w", dtmToday)

Select Case dtmDOW
    Case 1 MsgBox "Sunday"
    Case 2 MsgBox "Monday"
ETC...

Open in new window



Simple Ping
objShell.Run can also be used to /registerdns
 
boolPing = Not CBool(objShell.run("ping -n 2 " & strComputer, 0, True))
      If boolPing = True Then
         
      Else

Open in new window


More Variables for Shares and Copies
 
fServer = "\\fServer"
pServer = "\\pServer"
strSrc1 = "\\Server_1\Share_2"
strDest1 = "C:\Folder1"
strSrc2 = "\\Server_2\Share_3"
strDest2 = "C:\Folder2"

Open in new window


AD Connection
 
Set objWinntUser = GetObject("WinNT://" & objNetwork.UserDomain & "/" & objNetwork.UserName & ",user")

Open in new window


Verify Group Membership, Map and Copy
 
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG1) = True Then
    objNetwork.MapNetworkDrive "F:", "\\Server_1\Share_1", 0, True
    objNetwork.MapNetworkDrive "P:", "\\Server_1\Share_2", 0, True
    objFSO.CopyFile strSrc1, strDest1
End If

Open in new window

iedenAuthor Commented:
Did I mention I'm not the sharpest crayon in the box?
@yelbaglf: although I understand your descriptions of what the snippets do, I wouldn't know what to edit... I mean, if you could highlight or bold the word or phrase I may need to change...
Currently, we map network drives with .bat files applied by GPO's
@echo off
net use F: /delete
net use F: \\serve.domain.prvr\share
copy F:\dir\file.txt c:\dir /y /s
next
\\domain.prv\sysvol\ifmember.exe group2
net use S: /delete
net use S: \\server\share2
exit
Webinar: Cyber Crime Becomes Big Business

The rising threat of malware-as-a-service is not one to be overlooked. Malware-as-a-service is growing and easily purchased from a full-service cyber-criminal store in a “Virus Depot” fashion. Join us in our upcoming webinar as we discuss how to best defend against these attacks!

yelbaglfCommented:
Something like the below might do the trick, but I haven't tested it.  Everything in bold will need to be changed to their appropriate values/names, and if you need more of something, just add them.  For example if you need more strSrc (Source Copy) and strDest (Destination Copy), just add them to the script underneath what's existing.

If you need more Security Groups, then just add more strSG constants.  Remember that everything listed as 'Define variables or 'Something is a comment, and for display purposes, they are italicized.  Hopefully this helps and makes more sense.

Please take a stab at updating it and testing it, and let me know how it goes.  Also, let me know if you run across any questions.

'Basic error handling
On Error Resume Next

'Define variables
Dim objFSO
Dim fServer
Dim pServer
Dim objNetwork
Dim objWinntUser

'Define Constants
Const strSG1 = "Billing"
Const strSG2 = "HR"

Set objShell=CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Put me to sleep for 10 seconds
WScript.Sleep 10000

'Message box display DOW with OK
dtmToday = Date()
dtmDOW = DatePart("w", dtmToday)

Select Case dtmDOW
    Case 1 MsgBox "Sunday"
    Case 2 MsgBox "Monday"
    Case 3 MsgBox "Tuesday"
    Case 4 MsgBox "Wednesday"
    Case 5 MsgBox "Thursday"
    Case 6 MsgBox "Friday"
    Case 7 MsgBox "Saturday"
End Select

'Ping node
strComputer = "ComputerName_Ping"
boolPing = Not CBool(objShell.run("ping -n 2 " & strComputer, 0, True))
      If boolPing = True Then
         
      Else
         boolPing = Not CBool(objShell.run("ping -n 2 " & strComputer, 0, True))
         If boolPing = True Then
         
         Else
              WScript.Quit
         End If
      End If

'registerdns
ipReg = objShell.run("ipconfig /registerdns" & strComputer, 0, True)

'Set variable values
fServer = "\\fServer"
pServer = "\\pServer"
strSrc1 = "\\Server_1\Share_2"
strDest1 = "C:\Folder1"
strSrc2 = "\\Server_2\Share_3"
strDest2 = "C:\Folder2"

'**** AD connection ****
Set objWinntUser = GetObject("WinNT://" & objNetwork.UserDomain & "/" & objNetwork.UserName & ",user")

'**** Begin group verification, map printers or shares, and copy files ****
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG1) = True Then
    objNetwork.MapNetworkDrive "F:", "\\Server_1\Share_1", 0, True
    objNetwork.MapNetworkDrive "P:", "\\Server_1\Share_2", 0, True
    objFSO.CopyFile strSrc1, strDest1
End If
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG2) = True Then
    objNetwork.MapNetworkDrive "V:", "\\Server_2\Share_3", 0, True
    objNetwork.MapNetworkDrive "S:", "\\Server_1\Share_2", 0, True
    objFSO.CopyFile strSrc2, strDest2
End If
yelbaglfCommented:
Just in case you ever have some free time and would like to read up on this, EE has some great articles on the subject.  I know how free time is though, we Admins never get it! :-)

Several Part Series
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScript-for-Windows-System-Administrators-Part-1.html?sfQueryTermInfo=1+30+vbscript

Another VBScript for Windows Sys Admins Article
 http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_3315-VBScript-for-Windows-System-Administrators-Common-VBS-Myths-Dispelled-The-Missing-Prequel.html?sfQueryTermInfo=1+30+vbscript
Daz_1234Commented:
Note to yelbaglf:

If you are going to call the IsMemberOfGroup function, you will need to include it in your script.

Function IsMemberOfGroup(strUserDomain, objUser, strGroup)
      IsMemberOfGroup = False
      Dim objGroup
      On Error Resume Next
      Set objGroup = GetObject("WinNT://" & strUserDomain & "/" & strGroup & ",group")
      If Err.Number Then
            IsMemberOfGroup = "Error"
      Else
            IsMemberOfGroup = objGroup.IsMember(objUser.ADsPath)
      End If
End Function

Open in new window


[taken from Rob Sampson's code here: http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_23177557.html]

Regards,
Daz.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yelbaglfCommented:
Daz_1234 makes a good point in that you can call it as a function, but this isn't necessary.  The idea here was to do something simple, so that it would be easier to understand, and it actually works just fine without being called as a function.  When the script runs, it connects to AD, and then it works through the If, Else statements, mapping appropriately.
yelbaglfCommented:
Scratch that...just ran it, and it failed. :-)  I knew I should have tested it first.  Add this to the bottom of your script, as stated by Daz_1234.

 
Function IsMemberOfGroup(strUserDomain, objUser, strGroup)
    IsMemberOfGroup = False
    Dim objGroup
    On Error Resume Next
    Set objGroup = GetObject("WinNT://" & strUserDomain & "/" & strGroup & ",group")
    If Err.Number Then
        IsMemberOfGroup = "Error"
    Else
        IsMemberOfGroup = objGroup.IsMember(objUser.ADsPath)
    End If
End Function

Open in new window

iedenAuthor Commented:

Yup, I'm confused...
So that last part has me as close to migraine as I've ever been.

I'm working away trying to incorporate our environment and I'm not sure what I'm doing will work anyway.


Back to my original question for starters;

Day of week...
I'm looking for the message to pop on a day of week for a particular group of users.

Monday, users in an AD group named Sales

Tuesday, users in a group named Finance and another group named Billing

Wednesday, users in Executives.

Thursday, etc...



Each Group is also in an OU of their own if that helps...
OU=ARBilling,OU=Dallas,OU=GRP,OU=My Corp,DC=LARD,DC=CSG,DC=PRV
OU=ARExecutive,OU=Dallas,OU=GRP,OU=My Corp,DC=LARD,DC=CSG,DC=PRV
OU=ARFinance,OU=Dallas,OU=GRP,OU=My Corp,DC=LARD,DC=CSG,DC=PRV
OU=ARSales,OU=Dallas,OU=GRP,OU=My Corp,DC=LARD,DC=CSG,DC=PRV

Of corse the users are in groups within those OU's like this one...
CN=AllBillingUsers,OU=ARBilling,OU=Dallas,OU=GRP,OU=My Corp,DC=LARD,DC=CSG,DC=PRV
CN=AllExecutives,OU=ARExecutive,OU=Dallas,OU=GRP,OU=My Corp,DC=LARD,DC=CSG,DC=PRV
CN=AllFinanceUsers,OU=ARFinance,OU=Dallas,OU=GRP,OU=My Corp,DC=LARD,DC=CSG,DC=PRV
CN=AllSalesUsers,OU=ARSales,OU=Dallas,OU=GRP,OU=My Corp,DC=LARD,DC=CSG,DC=PRV





Now, The message should display for at least 5 seconds or until the user clicks OK.


I think the Ping part is pretty straight forward and have tested that working.



There is a section that looks like this:
'Defines Constants

Const strSG1 = "Sales"

Const strSG2 = "Billing"
How many of these Const strSG#'s can I use? strSG20 - strSG30?

Should the Const strSG# = "name" be the same as AD groups?

The ipconfig /registerdns seems pretty straightforward as well.

Because I am not the brightest bulb on the tree, I have to ask:
What is the difference between a fServer and a pServer?
yelbaglfCommented:
The day of the week shouldn't be a problem.  I'm thinking we can use vbscript's popup with a timeout for this.  I'll see what I can put together.

As for the constants, you can define as many as you need to use in the various parts of your script.  When declaring constants or variables, it's always easiest to choose something that makes sense, and then as you script in later life, reuse those same constants and variables.  So in this scenario, where we have strSG# = 'name', you'll want 'name' = 'Full Security Group Name'.  So if one group is 'Billing', then strSG# = "Billing".  If another is 'Bill and Ted', then strSG# = "Bill and Ted".  

Lastly, fServer and pServer are just variable names that I made up, and they can be changed to anything you'd like really.  But in this case, I have them representing File Server and Print Server respectively.
yelbaglfCommented:
As for the last part regarding the Function that was posted, if this isn't in the script, then the script will map all shares or printers or whatever, irregardless of group membership.  So in order for us to test group membership with IsMember, then we'll need the function included.  I reposted the script with this included.  Notice all I did was put it at the end of the script.

 
'Basic error handling
On Error Resume Next 

'Define variables
Dim objFSO
Dim fServer
Dim pServer
Dim objNetwork
Dim objWinntUser

'Define Constants
Const strSG1 = "Billing"
Const strSG2 = "HR"

Set objShell=CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Put me to sleep for 10 seconds
WScript.Sleep 10000

'Message box display DOW with OK
dtmToday = Date()
dtmDOW = DatePart("w", dtmToday)

Select Case dtmDOW
    Case 1 MsgBox "Sunday"
    Case 2 MsgBox "Monday"
    Case 3 MsgBox "Tuesday"
    Case 4 MsgBox "Wednesday"
    Case 5 MsgBox "Thursday"
    Case 6 MsgBox "Friday"
    Case 7 MsgBox "Saturday"
End Select

'Ping node
strComputer = "ComputerName_Ping"
boolPing = Not CBool(objShell.run("ping -n 2 " & strComputer, 0, True))
      If boolPing = True Then
         
      Else
         boolPing = Not CBool(objShell.run("ping -n 2 " & strComputer, 0, True))
         If boolPing = True Then
         
         Else
              WScript.Quit
         End If
      End If

'registerdns
ipReg = objShell.run("ipconfig /registerdns" & strComputer, 0, True)

'Set variable values
fServer = "\\fServer"
pServer = "\\pServer"
strSrc1 = "\\Server_1\Share_2"
strDest1 = "C:\Folder1"
strSrc2 = "\\Server_2\Share_3"
strDest2 = "C:\Folder2"

'**** AD connection ****
Set objWinntUser = GetObject("WinNT://" & objNetwork.UserDomain & "/" & objNetwork.UserName & ",user")

'**** Begin group verification, map printers or shares, and copy files ****
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG1) = True Then
    objNetwork.MapNetworkDrive "F:", "\\Server_1\Share_1", 0, True
    objNetwork.MapNetworkDrive "P:", "\\Server_1\Share_2", 0, True
    objFSO.CopyFile strSrc1, strDest1
End If
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG2) = True Then
    objNetwork.MapNetworkDrive "V:", "\\Server_2\Share_3", 0, True
    objNetwork.MapNetworkDrive "S:", "\\Server_1\Share_2", 0, True
    objFSO.CopyFile strSrc2, strDest2
End If 

Function IsMemberOfGroup(strUserDomain, objUser, strGroup)
    IsMemberOfGroup = False
    Dim objGroup
    On Error Resume Next
    Set objGroup = GetObject("WinNT://" & strUserDomain & "/" & strGroup & ",group")
    If Err.Number Then
        IsMemberOfGroup = "Error"
    Else
        IsMemberOfGroup = objGroup.IsMember(objUser.ADsPath)
    End If
End Function

Open in new window

yelbaglfCommented:
So let's say you decide you want to declare the following:

strSG1 = AllSalesUsers
strSG2 = AllFinanceUsers
strSG3 = AllBillingUsers
strSG4 = AllExecutives


And from your previous post, we know that strSG1, which is AllSalesUsers, should receive a popup if it is Monday.  The popup should display for 5 seconds, and it should have an OK button to dismiss it.

strSG2, which is AllFinanceUsers, should receive a popup in the same way, but ONLY on Tuesdays, and strSG3, which is AllBillingUsers, should receive this same Tuesday popup as well.

strSG4, which is AllExecutives, should receive a popup if it's Wednesday, and it should display for 5 seconds and have an OK button to dismiss it just the same.

From here the relevant portion of our code will look something like this...

'Define Constants
strSG1 = AllSalesUsers
strSG2 = AllFinanceUsers
strSG3 = AllBillingUsers
strSG4 = AllExecutives

'Message box display DOW with OK
dtmToday = Date()
dtmDOW = DatePart("w", dtmToday)

'**** Begin group verification, map printers or shares, and copy files ****
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG1) = True Then
    objNetwork.MapNetworkDrive "F:", "\\Server_1\Share_1", 0, True
    objNetwork.MapNetworkDrive "P:", "\\Server_1\Share_2", 0, True
    objFSO.CopyFile strSrc1, strDest1
    If dtmDOW = 2 Then
            strMon = objShell.Popup("Monday",5,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG2) = True Then
    objNetwork.MapNetworkDrive "F:", "\\Server_1\Share_1", 0, True
    objNetwork.MapNetworkDrive "P:", "\\Server_1\Share_2", 0, True
    objFSO.CopyFile strSrc1, strDest1
    If dtmDOW = 3 Then
            strMon = objShell.Popup("Tuesday",5,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG3) = True Then
    objNetwork.MapNetworkDrive "F:", "\\Server_1\Share_1", 0, True
    objNetwork.MapNetworkDrive "P:", "\\Server_1\Share_2", 0, True
    objFSO.CopyFile strSrc1, strDest1
    If dtmDOW = 3 Then
            strMon = objShell.Popup("Tuesday",5,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG4) = True Then
    objNetwork.MapNetworkDrive "F:", "\\Server_1\Share_1", 0, True
    objNetwork.MapNetworkDrive "P:", "\\Server_1\Share_2", 0, True
    objFSO.CopyFile strSrc1, strDest1
    If dtmDOW = 4 Then
            strMon = objShell.Popup("Wednesday",5,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If
iedenAuthor Commented:
Only issue I see with what you have above is the DOW popup needs to occur before the mapping of the drive. It's a timing thing that we need to have in place.

I think I may be able to figure something out on what you have written above,

The script will undoubtedly be very large, several hundred lines to incorporate everything I'm looking for.

Is this example plausible?
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG1) = True Then
    If dtmDOW = 2 Then
            strMon = objShell.Popup("Monday",5,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If

I'll just have to include a segment like the above for each group and then continue with a segment containing the mappings thereafter. Maybe...
yelbaglfCommented:
Exactly, you'll have to perform a test for security group membership at the point in the script that you'd like to have the popup.  And then another for the drive mappings, etc.
iedenAuthor Commented:
I'm losing it...
iedenAuthor Commented:
I'm a little lost here...
According to my limited understanding, this will pop up a message... I don't think it will pop up the message I want but something will show to the users referenced in the strSG## group...
'Message box display DOW with OK
dtmToday = Date()
dtmDOW = DatePart("w", dtmToday)

Select Case dtmDOW
    Case 1 MsgBox "Today is Sunday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete."
    Case 2 MsgBox "Today is Monday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete."
    Case 3 MsgBox "Today is Tuesday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete."
    Case 4 MsgBox "Today is Wednesday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete."
    Case 5 MsgBox "Today is Thursday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete."
    Case 6 MsgBox "Today is Friday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete."
    Case 7 MsgBox "Today is Saturday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete."
End Select

If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG40) = True Then
    If dtmDOW = 1 Then
            strMon = objShell.Popup("Sunday",5,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG41) = True Then
    If dtmDOW = 2 Then
            strMon = objShell.Popup("Monday",5,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG42) = True Then
    If dtmDOW = 3 Then
            strMon = objShell.Popup("Tuesday",5,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG43) = True Then
    If dtmDOW = 4 Then
            strMon = objShell.Popup("Wednesday",5,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG44) = True Then
    If dtmDOW = 5 Then
            strMon = objShell.Popup("Thursday",5,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG45) = True Then
    If dtmDOW = 6 Then
            strMon = objShell.Popup("Friday",5,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG46) = True Then
    If dtmDOW = 7 Then
            strMon = objShell.Popup("Saturday",5,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If

 

Open in new window

I'd like the messages typed out display in those popup boxes...
yelbaglfCommented:
So this portion determines which day of the week it is.

 
dtmToday = Date()
dtmDOW = DatePart("w", dtmToday)

Open in new window


And this portion can be removed, since we're not using it anymore.  This portion was initially being used to display the DOW for all users, but since you are wanting to test security group membership first, then we'll not use it.

 
Select Case dtmDOW
    Case 1 MsgBox "Today is Sunday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete."
    Case 2 MsgBox "Today is Monday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete."
    Case 3 MsgBox "Today is Tuesday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete."
    Case 4 MsgBox "Today is Wednesday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete."
    Case 5 MsgBox "Today is Thursday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete."
    Case 6 MsgBox "Today is Friday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete."
    Case 7 MsgBox "Today is Saturday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete."
End Select

Open in new window


This portion will test for security group membership, and then display the popup with whatever message is written within the first set of quotes: strMon = objShell.Popup("This is where you put the message",5 is the number of seconds to display, "Day of Week" is the pop window's title.  My understanding was that you wanted to display the day of the week to the end user, dependant upon which security group the user is a member of and only on the day you specified?  If this is correct, then the below will do that.

 
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG40) = True Then
    If dtmDOW = 1 Then
            strMon = objShell.Popup("Sunday",5,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If

Open in new window


As a side note...this here actually returns the day of the week as an integer, which is why we test with If dtmDOW = #.

dtmToday = Date()
dtmDOW = DatePart("w", dtmToday

So in order to place the sentence in the popup, you'll type it between the first set of quotes like this.

 
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG40) = True Then
    If dtmDOW = 1 Then
            strMon = objShell.Popup("Today is Sunday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete.",5,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If

Open in new window

iedenAuthor Commented:
You are being very patient and kind with me.
I'm under a little more than some pressure to get this solution in place before the begining of next week. So I am very grateful for your assitance.
Undoubtedly I will be asking for some clarification and a review of the final script. Somethign I guess I could be partly proud of. :-)
yelbaglfCommented:
You are most welcome!  And I have to say, you are doing a fantastic job, and before you know it, you'll be finding all types of things to script for your environment!

I absolutely will keep an eye out for your next post, and I'll be more than happy to take a final look.  I'm here till we get it working the way you need it.
iedenAuthor Commented:
Are we still using the section that looks like this:
'Set variable values
aServer = "\\server\root\Sales"
bServer = "\\server\root\Billing"
cServer = "\\server\root\Finance"
strSrc1 = "F:\Script\Log\docfile.txt"
strDest1 = "C:\logs /y"
strSrc2 = "F:\Script\Log\docattr.txt"
strDest2 = "C:\logs2 /y"

Open in new window

I don't see the variables in any lines... I mean, I see the strSrc1 & 2 and the strDest1 & 2 but not the servers...
yelbaglfCommented:
I don't recall what aServer, bServer, and cServer are doing.  Is this for the copy portion or drive mapping portion?  All that's required for 'CopyFile' or 'CopyFolder' is a source and destination, which would be the strSrc# and strDest#.

The drive mapping can use a variable as well, or you may choose to just type in the UNC path.  I find variables easier to manage in the long-term.  So if aServer, bServer, and cServer are for this, then yes we can use them.  You can do either of these:


objNetwork.MapNetworkDrive "F:", "\\Server_1\Share_1", 0, True   'Drive mapping with UNC path
objNetwork.MapNetworkDrive "P:", aServer, 0, True   'Drive mapping with defined variable
objFSO.CopyFile strSrc1, strDest1   'This is for copying a file from source to destination
objFSO.CopyFolder strSrc1, strDest1     'This is for copying a folder from source to destination

Open in new window

iedenAuthor Commented:
so the variable aserver does not have to be in quotations in order to work but a specific "\\server\share" would be?
yelbaglfCommented:
Absolutely correct!  I'm not sure if this helps, but here's a quick tutorial about variables.

http://www.w3schools.com/vbscript/vbscript_variables.asp
iedenAuthor Commented:
This weekend has been a bit tough to do any testing, our company did a datacenter power down to tighten all electrical connectors and install a new UPS management interface, replaced two core switches and hardware disk controllers on our power iSeries systems.. Lots of work and no freedom to do the other things. Will get back to testing shortly. Plus, I reloaded my computer Wednesday :-) should be back to testing this in a day or two. After all users have had their issues addressed from the power down
yelbaglfCommented:
Sounds good!  Good Luck!
iedenAuthor Commented:
OK, so I've tried testing an abbreviated script. Perhaps I am doing something wrong, IDK. The contents of which are as follows:
'***Basic error handling***
On Error Resume Next 

'***Define variables***
Dim objFSO
Dim fServer
Dim pServer
Dim objNetwork
Dim objWinntUser

'***Define Constants***
Const strSG40 = "NACSun"
Const strSG41 = "NACMon"
Const strSG42 = "NACTue"
Const strSG43 = "NACWed"
Const strSG44 = "NACThu"
Const strSG45 = "NACFri"
Const strSG46 = "NACSat"

Set objShell=CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")

'***Put me to sleep for 10 seconds***
'WScript.Sleep 10000

'***Message box display DOW with OK***
dtmToday = Date()
dtmDOW = DatePart("w", dtmToday)
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG40) = True Then
    If dtmDOW = 1 Then
            strMon = objShell.Popup("Today is Sunday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete.",15,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG41) = True Then
    If dtmDOW = 2 Then
            strMon = objShell.Popup("Today is Monday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete.",15,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG42) = True Then
    If dtmDOW = 3 Then
            strMon = objShell.Popup("Today is Tuesday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete.",15,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG43) = True Then
    If dtmDOW = 4 Then
            strMon = objShell.Popup("Today is Wednesday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete.",15,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG44) = True Then
    If dtmDOW = 5 Then
            strMon = objShell.Popup("Today is Thursday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete.",15,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG45) = True Then
    If dtmDOW = 6 Then
            strMon = objShell.Popup("Today is Friday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete.",15,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If
If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strSG46) = True Then
    If dtmDOW = 7 Then
            strMon = objShell.Popup("Today is Saturday. Your computer will be scanned by the NAC device. Please be patient as this may take several minutes to complete.",15,"Day of Week",vbOKOnly)
      Else
            'WScript.Echo "Not Monday"
      End If
End If

Open in new window

Now, you know I'm no expert at getting these things working but I figured I would start with the hard stuff first. The groups referenced have other groups in them I am nesting AD groups to get the desired effect and shorten the number of lines required to code. If this is wrong, let me know now so I can start rewritting.
Daz_1234Commented:
You must include the lines below in your script: I would put them at the end.  This is the function that you are calling to establish if the user is a member of the group.
'Add this function to your code in order to use it!!!
Function IsMemberOfGroup(strUserDomain, objUser, strGroup)
      IsMemberOfGroup = False
      Dim objGroup
      On Error Resume Next
      Set objGroup = GetObject("WinNT://" & strUserDomain & "/" & strGroup & ",group")
      If Err.Number Then
            IsMemberOfGroup = "Error"
      Else
            IsMemberOfGroup = objGroup.IsMember(objUser.ADsPath)
      End If
End Function

Open in new window

If IsMemberOfGroup etc. is not a standard VBScript command, it is a call to the function I have pasted above (originally written by Rob Sampson).

One of the biggest mistakes being made here is using 'On Error Resume Next' for testing and troubleshooting.  Once the script is all perfect and robust, you can think about hiding any errors.

Allow me to demonstrate.  In the following code, there is an error at line 1 "Type mismatch: 'IsMemberOfGroup'"
If IsMemberOfGroup("DOM", "USER", "somestring") = True Then
   MsgBox "True"
Else
   MsgBox "False"
End If

Open in new window

... but in the following code, the If always returns 'True', because the On Error Resume Next is covering up the error (which is that the function does not exist and IsMemberOfGroup is not an array).
On Error Resume Next

On Error Resume Next

If IsMemberOfGroup("DOM", "USER", "somestring") = True Then
   MsgBox "True"
Else
   MsgBox "False"
End If

Open in new window



Regards,
Daz.
iedenAuthor Commented:
Got into a little more of the sleep command... It appears that sleep does not work with Windows 7. Whereas timeout does work for both Win7 and XP. So I'm playing around with that a bit. Still can't get DOW to popup in testing. Seems like this may be a bit too complicated or our network is too diverse to get a cohesive script to run on all PC's...
Trying to learn this stuff is a bit more complicated the older you get. I'm conceding my age is a factor in this and I'm only 48...
yelbaglfCommented:
I tested the very last script post of yours, and it works fine for me on Windows 7 and XP 32-bit.  The 'sleep' command also works for me on Windows 7 and XP.  BUT there are 2 things your last post is missing...

The first is the IsMemberOfGroup function...just add this to the very bottom of your script.

 
Function IsMemberOfGroup(strUserDomain, objUser, strGroup)
    IsMemberOfGroup = False
    Dim objGroup
    On Error Resume Next
    Set objGroup = GetObject("WinNT://" & strUserDomain & "/" & strGroup & ",group")
    If Err.Number Then
        IsMemberOfGroup = "Error"
    Else
        IsMemberOfGroup = objGroup.IsMember(objUser.ADsPath)
    End If
End Function

Open in new window


The second thing you're missing is the Active Directory connection, which is required in order for the IsMemberOfGroup function to test for security group membership.  Just paste this immediately after your 'sleep' command.

 
'**** AD connection ****
Set objWinntUser = GetObject("WinNT://" & objNetwork.UserDomain & "/" & objNetwork.UserName & ",user")

Open in new window

yelbaglfCommented:
I meant to ask how you're testing your script?  Are you just running it while logged in, or are you letting it run as a logon script?
iedenAuthor Commented:
I have a test ou and a test user with administrative rights to the workstation. Both the computer and user are in the test ou. The test PC is WinXP
I also have linked to the policy to my ou and added myself as the target. The domain is 2008r2 fully upgraded My workstation is Win764bit. I run with admin privs...
yelbaglfCommented:
Are you seeing that it runs more consistently on XP than on Win 7?  If so, something that we do in our environment, and this has been a challenge for many, is use group policy to force the PC's to wait until the network is initialized.  After setting this GPO, our scripts run flawlessly between disparate OS's.

Here's the KB which talks about this GPO.
http://support.microsoft.com/kb/304970
yelbaglfCommented:
While I don't have a 64-bit Win 7 machine, I was able to test this on Server 2008 R2 which is 64-bit, and it was successful.  The GPO I posted earlier should help you get this working consistently.

Another way to test would be to copy the script over to your desktop, and then you can just run it by double-clicking it.
iedenAuthor Commented:
Although the complete script is unfinished at this time, it is unfair to keep this thread open. You all have been very patient and kind with me. Split points to all answers that contributed.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.