944,126 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 7338
  • VB.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
May 24th, 2005
0

Problems writing script which checks the users group and date

Expand Post »
Hello

I have not had much programming experience especially with VBS. I have been asked to write a script which checks what AD group a user is in and then runs a specific drive mappings for that group and user, also i need the script to check the date. This is needed so that (for example) on Friday when the user logs on they recieve additional drives or an application starts.

This is what i have so far............

VB.NET Syntax (Toggle Plain Text)
  1. on error resume next
  2.  
  3. Dim WshNetwork, strUserName
  4.  
  5. Set WshNetwork = CreateObject("WScript.Network")
  6.  
  7. strUserName = wshnetwork.Username
  8.  
  9. wshnetwork.MapNetworkDrive "w:", "\\Server_name\Departments"
  10.  
  11. If IsMember(WshNetwork.username, "user_name") Then
  12.  
  13. wshnetwork.MapNetworkDrive "z:", "\\Server_name\departments\user_name"
  14. wshnetwork.MapNetworkDrive "I:", "\\Server_name\Another_folder"
  15. wshnetwork.MapNetworkDrive "O:", "\\Server_name\Another_folder"
  16. wshnetwork.MapNetworkDrive "P:", "\\Server_name\Another_folder"
  17. wshnetwork.MapNetworkDrive "V:", "\\Server_name\Another_folder"
  18.  
  19. End if
  20.  
  21. wscript.quit
.................................

This works fine for me (one person) what i need to get is instead of it just running for me i need it to check the group. Also i need to check the date so that if the date is, for example, Friday they get an app open when the user logs on.

I hope this makes some sence to someone as i think i lost myself while typing!!! :o

Any help would be appriciated

Thank you

Gareth Collins
Reputation Points: 10
Solved Threads: 0
Newbie Poster
grc1uk is offline Offline
15 posts
since May 2005
May 24th, 2005
0

Re: Problems writing script which checks the users group and date

I'm not 100% sure what an AD Group is.... if you can give me a little more light on that subject, I can probably help you out. As for retrieving the Day of the Week (say, Sunday - Saturday), I have written a function that returns the day of the week from the current day. Here is that function, just stick it at the very very bottom of your script (like, after wscript.quit):

VB.NET Syntax (Toggle Plain Text)
  1. public function ReturnDay
  2. RawDate = FormatDateTime(Now(), 1)
  3. Parts = split(RawDate, ",")
  4. ReturnDay = Parts(0)
  5. end function

And you can call that function like this:
VB.NET Syntax (Toggle Plain Text)
  1. TheDay = ReturnDay()

You would probably use it like so:
VB.NET Syntax (Toggle Plain Text)
  1. TheDay = ReturnDay()
  2.  
  3. if Theday = "Friday" then
  4. ' /* Do Stuff Here For Friday */
  5. else
  6. ' /* Do Stuff Here For Every Other Day */
  7. end if

If you can get me a little more info on "AD", I'll see what I can do about retrieving the Group that the user belongs to.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 24th, 2005
0

Re: Problems writing script which checks the users group and date

Thanks for the responce. AD = Active Directory, where in an organisation you put your users and groups. Hope that helps. I have found some code that might actually help me with this...

VB.NET Syntax (Toggle Plain Text)
  1. Option Explicit
  2. Dim objNetwork, objUser, CurrentUser
  3. Dim strGroup
  4.  
  5. Const Admin_Group = "cn=oly_users_admin"
  6. Const Managers_Group = "cn=oly_users_manager"
  7. Const Accounting_Group = "oly_users_accounting"
  8. Const Estimate_Group = "cn=oly_users_estimate"
  9. Const Design_East_Group = "cn=oly_design_east"
  10. Const Design_West_Group = "cn=oly_design_west"
  11. Const All_Users_Group = "cn=oly_users_all"

Some thing along the line of the above is what i will need to write.

With regards to the posting that you made with the time, thanks.. I am still trying to get it working. What i am trying is to get it to display a simple .htm file every Tuesday to all people who will run the script when they log on to the computer.

So far this is the code i am using for this (mainly thanks to your post)...

VB.NET Syntax (Toggle Plain Text)
  1. public function ReturnDay
  2. RawDate = FormatDateTime(Now(), 1)
  3. Parts = split(RawDate, ",")
  4. ReturnDay = Parts(0)
  5. end function
  6.  
  7. TheDay = ReturnDay()
  8.  
  9. if Theday = "Tuesday" then
  10.  
  11. shell ("C:\progra~1\intern~1\iexplore.exe file://cih_data\IT\Public\CIHStaffNews.htm")
  12.  
  13. else
  14.  
  15. end if
----------

Any ideas why this is not calling this .htm from a file shared network drive??

Thanks again for your help
Reputation Points: 10
Solved Threads: 0
Newbie Poster
grc1uk is offline Offline
15 posts
since May 2005
May 24th, 2005
0

Re: Problems writing script which checks the users group and date

Quote ...
"file://cih_data\IT\Public\CIHStaffNews.htm"
You Have a mapped drive called cih_data?

VB.NET Syntax (Toggle Plain Text)
  1. dim oIE
  2. Set oIE = WScript.CreateObject("InternetExplorer.Application")
  3.  
  4. TheDay = ReturnDay()
  5.  
  6.  
  7. if Theday = "Tuesday" then
  8. oIE.Navigate "file://cih_data\IT\Public\CIHStaffNews.htm"
  9. oIE.Show
  10. set oIE = nothing
  11. else
  12.  
  13. end if
  14.  
  15. WScript.Quit
  16.  
  17.  
  18. public function ReturnDay
  19. RawDate = FormatDateTime(Now(), 1)
  20. Parts = split(RawDate, ",")
  21. ReturnDay = Parts(0)
  22. end function
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 24th, 2005
0

Re: Problems writing script which checks the users group and date

And For Access Groups, it looks like you have it pretty well in play, but here is a link to a site that has a function and sample code for working with ADS with VBScript.
http://www.activexperts.com/activmon...mPrimGroup.htm
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 24th, 2005
0

Re: Problems writing script which checks the users group and date

Again, thank you.

The share is acutally the server name cih_data. I have tried that code but it still will not display that file, can you think of anyhthing i am doing wrong. I have basically copied your code from the preivous post

Thanks

Gareth
Reputation Points: 10
Solved Threads: 0
Newbie Poster
grc1uk is offline Offline
15 posts
since May 2005
May 24th, 2005
0

Re: Problems writing script which checks the users group and date

Yes, I'm pretty sure that IE has no idea what that share is. If it was assigned a drive letter, that might be a different story... but because it's not, I'm willing to bet that IE has no clue what it's looking at. If you could assign the share a drive letter, it should probably work.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 24th, 2005
0

Re: Problems writing script which checks the users group and date

I have created a shared drive for this. G:

When trying this script...

VB.NET Syntax (Toggle Plain Text)
  1. dim oIE
  2. Set oIE = WScript.CreateObject("InternetExplorer.Application")
  3.  
  4. TheDay = ReturnDay()
  5.  
  6.  
  7. if Theday = "Tuesday" then
  8. oIE.Navigate "file://G:\CIHStaffNews.htm"
  9. oIE.Show
  10. set oIE = nothing
  11. else
  12.  
  13. end if
  14.  
  15. WScript.Quit
  16.  
  17.  
  18. public function ReturnDay
  19. RawDate = FormatDateTime(Now(), 1)
  20. Parts = split(RawDate, ",")
  21. ReturnDay = Parts(0)
  22. end function
...................

I am still getting nothing displayed. If i copy the link G:\cihstaffnews.htm in to the RUN command it file opens. So i know that the link is correct...

any ideas??
Reputation Points: 10
Solved Threads: 0
Newbie Poster
grc1uk is offline Offline
15 posts
since May 2005
May 24th, 2005
0

Re: Problems writing script which checks the users group and date

Oops. Just replace:
VB.NET Syntax (Toggle Plain Text)
  1. oIE.Show

with:
VB.NET Syntax (Toggle Plain Text)
  1. oIE.Visible = True
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 25th, 2005
0

Re: Problems writing script which checks the users group and date

I have changed the code but unfortunatly this is still not working. This is the code i have at present.

------------------
VB.NET Syntax (Toggle Plain Text)
  1. dim oIE
  2. Set oIE = WScript.CreateObject("InternetExplorer.Application")
  3.  
  4. public function ReturnDay
  5. RawDate = FormatDateTime(Now(), 1)
  6. Parts = split(RawDate, ",")
  7. ReturnDay = Parts(0)
  8. end function
  9.  
  10. TheDay = ReturnDay()
  11.  
  12.  
  13. if Theday = "Wednesday" then
  14. oIE.Navigate "file://G:\CIHStaffNews.htm"
  15. oIE.Visible = True
  16. set oIE = nothing
  17. else
  18.  
  19. end if
  20.  
  21.  
  22. WScript.Quit
----------------------

Thanks again for your help on this
Reputation Points: 10
Solved Threads: 0
Newbie Poster
grc1uk is offline Offline
15 posts
since May 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Application Block in asp.net using vb.net
Next Thread in VB.NET Forum Timeline: Unzip zipped xml file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC