Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

vbs to manipulate a link.


  • Please log in to reply
3 replies to this topic

#1 DVaD

DVaD

  • Members
  • 59 posts
  • OFFLINE
  •  
  • Local time:10:34 AM

Posted 27 September 2010 - 11:45 AM

Hi all,

I'm trying to create a vb script I can use to deploy through AD. Basically what I need to do is change the url and make sure the users have all the desktop icons in a new standard location. So far I can get the script to copy the desktop icons folder and copy the files over, unfortunately that's as far as it goes. any help would be appreciated. Here's my code.

[codebox]' Find file
Set oShell = CreateObject( "WScript.Shell" )
user=oShell.ExpandEnvironmentStrings("%UserName%")

Set filesys = CreateObject("Scripting.FileSystemObject")
If NOT filesys.FolderExists("C:\Desktop Icons") Then
filesys.CreateFolder("C:\Desktop Icons")
filesys.CopyFolder "\\server\apps\Desktop Icons", "C:\Desktop Icons"
End If

If filesys.FileExists("C:\Documents and Settings\" & user & "\Desktop\SC Self Service.lnk") Then
filesys.DeleteFile("C:\Documents and Settings\" & user & "\Desktop\SC Self Service.lnk") Then
CreateNew()
ElseIf filesys.FileExists("C:\Documents and Settings\All Users\Desktop\SC Self Service.lnk") Then
filesys.DeleteFile("C:\Documents and Settings\All Users\Desktop\SC Self Service.lnk")Then
CreateNew()
End If

function CreateNew()
Set oWS = WScript.CreateObject("WScript.Shell")
Set shortcut = ows.CreateShortcut("C:\Documents and Settings\All Users\Desktop\SC Self Service.lnk")
Set oLink = oWS.CreateShortcut(sLinkFile)

oLink.TargetPath = "http://wwwurl.com"
oLink.Description = "eP Self Service"
oLink.IconLocation = "C:\Desktop Icons\SSIcon.bmp"
oLink.Save
end function[/codebox]

Edited by DVaD, 27 September 2010 - 11:45 AM.


BC AdBot (Login to Remove)

 


#2 PropagandaPanda

PropagandaPanda


  • Malware Response Team
  • 10,433 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:11:34 AM

Posted 27 September 2010 - 04:24 PM

Hello.

Your code won't run because it has some stray "then"'s .

If filesys.FileExists("C:\Documents and Settings\" & user & "\Desktop\SC Self Service.lnk") Then
filesys.DeleteFile("C:\Documents and Settings\" & user & "\Desktop\SC Self Service.lnk") Then
CreateNew()
ElseIf filesys.FileExists("C:\Documents and Settings\All Users\Desktop\SC Self Service.lnk") Then
filesys.DeleteFile("C:\Documents and Settings\All Users\Desktop\SC Self Service.lnk")Then
CreateNew()
End If


If you are familier with C++, or any similar language in terms of blocking, "then" is equivalent to "{". ElseIf is equivalent to "} else if". "End If" is equivalent to "}" . Have a look here:
http://www.tizag.com/vbscriptTutorial/vbscriptelseif.php

Please clarify what exactly your are trying to accomplish. From what I can infer from the code, it looks like to you can do the same thing by creating the url link manually once, then copy it to whereever its needed, instead of creating a new one every time.

With Regards,
The Panda

#3 Romeo29

Romeo29

    Learning To Bleep


  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:10:34 AM

Posted 28 September 2010 - 12:33 PM

Function CreateNew()
Set oWS = WScript.CreateObject("WScript.Shell")
Set shortcut = ows.CreateShortcut("C:\Documents and Settings\All Users\Desktop\SC Self Service.lnk")
sLinkFile = oWS.SpecialFolders("Desktop") & "\SC Self Service.lnk"
Set oLink = oWS.CreateShortcut(sLinkFile)

oLink.TargetPath = "http://www.bleepingcomputer.com/"
oLink.Description = "eP Self Service"
oLink.IconLocation = "C:\Desktop Icons\SSIcon.ico"
oLink.Save

End Function

#4 DVaD

DVaD
  • Topic Starter

  • Members
  • 59 posts
  • OFFLINE
  •  
  • Local time:10:34 AM

Posted 28 September 2010 - 04:18 PM

Nevermind I got it all going. I used a template from a website, I'm gonna have to look at it tomorrow and try to learn how it works though. Heres the code.

[codebox]'Remove SC

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strDesktopPath = objShell.SpecialFolders("Desktop")
strAllDesktopPath = objShell.ExpandEnvironmentStrings("%allusersprofile%")&"\desktop"

DelShorts "shortcut to SC Self Service.lnk"
DelShorts "SC Self Service.lnk"

Function DelShorts(strShortcutName)
If objFSO.FileExists(strDesktopPath & "\" & strShortcutName) then objFSO.DeleteFile strDesktopPath & "\" & strShortcutName
If objFSO.FileExists(strAllDesktopPath & "\" & strShortcutName) then objFSO.DeleteFile strAllDesktopPath & "\" & strShortcutName
End Function[/codebox]

Edited by DVaD, 28 September 2010 - 04:29 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users