#1 13 Aug 2014 17:25

HellfireXD
Member
Registered: 13 Aug 2014
Posts: 5

Pulling Website from AD

Hello all,

  I am attempting to put together a VB Script to pull the user accounts web page address from active directory.

The purpose of this script is to Create a shortcut under "%Userprofile%\Links\" called "MySite".  This will link to the users MySite in SharePoint.
Unfortunately we have some older systems on our network that do not have powershell so i need to set this up on VB.
I can create the link just fine but am unsure how to pull the information I need from AD.

Not as seasoned in VB as i would like to be.

Thanks!

Offline

#2 13 Aug 2014 17:44

HellfireXD
Member
Registered: 13 Aug 2014
Posts: 5

Re: Pulling Website from AD

This is what i have so far,  it echos the webpage just fine however, it fails to create the link.

On Error Resume Next
Dim objSysInfo, objUser
Set objSysInfo = CreateObject("ADSystemInfo")

' Currently logged in User
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
 'or specific user:
 'Set objUser = GetObject("LDAP://CN=%username%,OU=Users,DC=YourDC,DC=com")

WScript.Echo "Web page: " & objUser.wWWHomePage

   Set objShell = WScript.CreateObject("WScript.Shell")
   Set lnk = objShell.CreateShortcut(objUser.wWWHomePage)
   
   lnk.TargetPath = "%userprofile%\Links\MySite"
   lnk.Arguments = ""
   lnk.Description = "MySite"
   lnk.HotKey = ""
   lnk.IconLocation = "%SystemRoot%\system32\SHELL32.dll, 150"
   lnk.WindowStyle = "1"
   lnk.WorkingDirectory = "%userprofile%\Links\"
   lnk.Save
   'Clean up 
	Set lnk = Nothing

Offline

#3 13 Aug 2014 20:07

HellfireXD
Member
Registered: 13 Aug 2014
Posts: 5

Re: Pulling Website from AD

Found an error in my code however, it is still not working.

On Error Resume Next
Dim objSysInfo, objUser
Set objSysInfo = CreateObject("ADSystemInfo")

' Currently logged in User
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
 'or specific user:
 'Set objUser = GetObject("LDAP://CN=%username%,OU=Users,DC=YourDC,DC=com")

WScript.Echo "Web page: " & objUser.wWWHomePage

   Set objShell = WScript.CreateObject("WScript.Shell")
   Set lnk = objShell.CreateShortcut("%userprofile%\Links\MySite")     ' Error fixed here
   
   lnk.TargetPath = "[b]objUser.wWWHomePage[/b]"     ' Error fixed here
   lnk.Arguments = ""
   lnk.Description = "MySite"
   lnk.HotKey = ""
   lnk.IconLocation = "%SystemRoot%\system32\SHELL32.dll, 150"
   lnk.WindowStyle = "1"
   lnk.WorkingDirectory = "%userprofile%\Links\"
   lnk.Save
   'Clean up 
	Set lnk = Nothing

Problem is that i need to create the shortcut as if it were a folder while using the URL to the SharePoint site.

In outlook if you go to attach a file and navigate to a SharePoint website using the URL you will get a web page you can save to your favorites as a folder type (UNC) shortcut. This seams to be the only way to create this type of shortcut as all other ways simply open in a folder view inside of outlook.  If you create a shortcut as normal using a URL, outlook will refuse to open it.

Recreating this anomaly via script is what i am attempting to do but has been extremely defiant.

Offline

#4 15 Aug 2014 11:25

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 900
Website

Re: Pulling Website from AD

A couple of things, first I think you need to unwrap objUser.wWWHomePage into a string before using it
strTemp=objUser.wWWHomePage

Second, this will create a shortcut (.lnk file) to a file or folder, so to have it open a web page you need to point the shortcut to iexplore.exe and also pass the url to internet explorer as an argument.

An easier method is to create a Favourite file (.url) you can create this in batch with a couple of echo statements:

Echo [InternetShortcut] > demo.url
Echo URL=http://ss64.com/ >> demo.url

Offline

#5 15 Aug 2014 13:54

HellfireXD
Member
Registered: 13 Aug 2014
Posts: 5

Re: Pulling Website from AD

Simon Sheppard wrote:

A couple of things, first I think you need to unwrap objUser.wWWHomePage into a string before using it
strTemp=objUser.wWWHomePage

Second, this will create a shortcut (.lnk file) to a file or folder, so to have it open a web page you need to point the shortcut to iexplore.exe and also pass the url to internet explorer as an argument.

An easier method is to create a Favourite file (.url) you can create this in batch with a couple of echo statements:

Echo [InternetShortcut] > demo.url
Echo URL=http://ss64.com/ >> demo.url

I actually want it to stay open in outlook and not in IE as it is for the dialog to attach documents. (Picture below)

The only way i have been able to do this is by starting a new email, opening the add attachment dialog and the browsing to the URL of the MySite for SharePoint. this opens it as a webpage, at this time i add the current location to favorites.

For the script I am attempting to replicate this without having to go out and touch over 1,000 computer systems in remote locations.

2014_08_15_084037.png

Offline

#6 15 Aug 2014 17:33

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 900
Website

Re: Pulling Website from AD

I'm a bit confused about what it is you are trying to do!

The web page address from active directory is not necessarily the same as the users MySite in SharePoint which is held in the SharePoint profile database (unless you have previously copied the url to AD for some other reason).

I suspect what you may need is this fix for opening the users MySite. With that in place, the users then just have to visit their mysite, which by default is on the standard SharePoint menu.
They will then have sharepoint places right in the open/save dialogue boxes without having to look for any custom shortcut.

Offline

#7 15 Aug 2014 21:13

HellfireXD
Member
Registered: 13 Aug 2014
Posts: 5

Re: Pulling Website from AD

We are putting the users My Site URL into the AD user object manually at creation, i should have specified that earlier. I will have to look into that fix you linked, it may be a better solution for us to implement in our network.

Something i found interesting about the favorite, if i create it as a URL and try to navigate to it in outlook it tells me that outlook cannot open the location.  If i enter the URL into the address bar manually it goes to it.  The webdav only seams to convert it if i type it in myself.  After typing it in and saving it to the favorites location is when it works as shown in the screenshot.

As for now i will be putting this script on the back burner and explore the solution you linked to.

Thanks for your help!

Offline

Board footer

Powered by FluxBB