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............

on error resume next

Dim WshNetwork, strUserName

Set WshNetwork = CreateObject("WScript.Network")

strUserName = wshnetwork.Username

wshnetwork.MapNetworkDrive "w:", "\\Server_name\Departments"

If IsMember(WshNetwork.username, "user_name") Then

wshnetwork.MapNetworkDrive "z:", "\\Server_name\departments\user_name"
   wshnetwork.MapNetworkDrive "I:", "\\Server_name\Another_folder"
   wshnetwork.MapNetworkDrive "O:", "\\Server_name\Another_folder"
   wshnetwork.MapNetworkDrive "P:", "\\Server_name\Another_folder"
   wshnetwork.MapNetworkDrive "V:", "\\Server_name\Another_folder"

End if

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

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

public function ReturnDay
	RawDate = FormatDateTime(Now(), 1)
	Parts = split(RawDate, ",")
	ReturnDay = Parts(0)
end function

And you can call that function like this:

TheDay = ReturnDay()

You would probably use it like so:

TheDay = ReturnDay()

if Theday = "Friday" then
     ' /* Do Stuff Here For Friday */
else
    ' /* Do Stuff Here For Every Other Day */
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.

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...

Option Explicit
Dim objNetwork, objUser, CurrentUser
Dim strGroup

Const Admin_Group = "cn=oly_users_admin"
Const Managers_Group = "cn=oly_users_manager"
Const Accounting_Group = "oly_users_accounting"
Const Estimate_Group = "cn=oly_users_estimate"
Const Design_East_Group = "cn=oly_design_east"
Const Design_West_Group = "cn=oly_design_west"
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)...

public function ReturnDay
	RawDate = FormatDateTime(Now(), 1)
	Parts = split(RawDate, ",")
	ReturnDay = Parts(0)
end function

TheDay = ReturnDay()

if Theday = "Tuesday" then
     
shell ("C:\progra~1\intern~1\iexplore.exe file://cih_data\IT\Public\CIHStaffNews.htm")
	
else

end if

----------

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

Thanks again for your help

"file://cih_data\IT\Public\CIHStaffNews.htm"

You Have a mapped drive called cih_data?

dim oIE
Set oIE = WScript.CreateObject("InternetExplorer.Application")

TheDay = ReturnDay()


if Theday = "Tuesday" then
	oIE.Navigate "file://cih_data\IT\Public\CIHStaffNews.htm"
	oIE.Show
	set oIE = nothing
else

end if

WScript.Quit


public function ReturnDay
	RawDate = FormatDateTime(Now(), 1)
	Parts = split(RawDate, ",")
	ReturnDay = Parts(0)
end function

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

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.

I have created a shared drive for this. G:

When trying this script...

dim oIE
Set oIE = WScript.CreateObject("InternetExplorer.Application")

TheDay = ReturnDay()


if Theday = "Tuesday" then
	oIE.Navigate "file://G:\CIHStaffNews.htm"
	oIE.Show
	set oIE = nothing
else

end if

WScript.Quit


public function ReturnDay
	RawDate = FormatDateTime(Now(), 1)
	Parts = split(RawDate, ",")
	ReturnDay = Parts(0)
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??

Oops. Just replace:

oIE.Show

with:

oIE.Visible = True

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

------------------

dim oIE
Set oIE = WScript.CreateObject("InternetExplorer.Application")

public function ReturnDay
	RawDate = FormatDateTime(Now(), 1)
	Parts = split(RawDate, ",")
	ReturnDay = Parts(0)
end function

TheDay = ReturnDay()


if Theday = "Wednesday" then
	oIE.Navigate "file://G:\CIHStaffNews.htm"
	oIE.Visible = True
	set oIE = nothing
else

end if


WScript.Quit

----------------------

Thanks again for your help on this

Have you tried replacing file://G:\CIHStaffNews.htm with an actual URL? Such as google or yahoo, to see if it actually loads a web page? After changing .show to .visible did the IE window actually show up, and now you are getting a different error?

I have changed it to www.google.co.uk, but this did not make any difference still nothing happening. IE does not open and i am getting no errors??

Any ideas?

Gareth

dim oIE
Set oIE = WScript.CreateObject("InternetExplorer.Application")



TheDay = ReturnDay()


if Theday = "Wednesday" then
	oIE.Navigate "www.google.com"
	oIE.Visible = True
else

end if
set oIE = Nothing
WScript.Quit

public function ReturnDay
	RawDate = FormatDateTime(Now(), 1)
	Parts = split(RawDate, ",")
	ReturnDay = Parts(0)
end function

This works perfectly fine on my machine. It spawns IE and loads google with no problem. Try to copy and paste the code I have posted here, into a document, and see if it works.

Nope sorry i still get nothing!!
When i run this is get a compile error and SET gets highlighted??

How are you running this??

I just double click on the icon and it runs. I'm guessing perhaps your version of windows doesn't have the latest IE installed, or the latest WSH installed, if at all (thought it should). That said, try it the first way:

TheDay = ReturnDay()

if Theday = "Wednesday" then
     shell ("C:\progra~1\intern~1\iexplore.exe file://G:\CIHStaffNews.htm")
else

end if

WScript.Quit

public function ReturnDay
	RawDate = FormatDateTime(Now(), 1)
	Parts = split(RawDate, ",")
	ReturnDay = Parts(0)
end function

I have added the following in to the code and now it is working

TheDay = WeekdayName(Weekday(Date))

Where as we had it saying

TheDay = ReturnDay()

HERES THE WORKING CODE

dim oIE
Set oIE = WScript.CreateObject("InternetExplorer.Application")


TheDay = WeekdayName(Weekday(Date))

if Theday = "Thursday" then
	oIE.Navigate "www.google.co.uk"
	oIE.Visible = True
else

end if
set oIE = Nothing

WScript.Quit

public function ReturnDay
	RawDate = FormatDateTime(Now(), 1)
	Parts = split(RawDate, ",")
	ReturnDay = Parts(0)
end function

Cheers for all your help mate..

Gareth

I certainly appreciate you posting the working code and solution. This way others have the ability to learn from what we had just struggled with. Good Job, and Congrats :)

No problem mate, just need to work it now so that does not appear when 2 computers are logged on to, but all the mappings are still there etc. Great fun ahead.

cheers again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.