How do I go about doing this?
Hi
You could run the following script in e.g. a logon script and write the result
to a text file:
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("scripting.FileSystemObject")
sSC = "QuickTime Player.lnk"
sDesktop = oShell.SpecialFolders("Desktop")
If oFSO.FileExists(sDesktop & "\" & sSC) Then
WScript.Echo "Link exists"
End If
--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter
>.
>
> Being so new to this I don't even know how to modify your
> script.
> As an example can you have the script look for a shortcut
> to excel on the desktop and then log to a test file on
> \\server\log\log.txt ?
Hi
Const ForAppending = 8
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
sRegVal = "" ' init value
sRegVal = LCase(oShell.RegRead("HKCU\Software\LinkTest\Excel"))
On Error GoTo 0
If sRegVal = "done" Then
' user has already run this script, quit
WScript.Quit
End If
sSC = "Excel.lnk"
sDesktop = oShell.SpecialFolders("Desktop")
' file to log to
sLogFile = "\\server\log\log.txt"
bUpdFinished = False ' init value
On Error Resume Next
Do
' open for appending
Set f = oFSO.OpenTextFile(sLogFile, ForAppending, True)
If Err.Number = 70 Then
' Permission denied error, somebody else is updating the file
' Waiting 1/2 a second before trying again
WScript.Sleep 500
ElseIf Err.Number <> 0 then
' Unexpected error, we give up
bUpdFinished = True
Else
On Error GoTo 0
' do the job here, the file will now be locked by this script and
' nobody else will be able to continue until the f.Close instruction
' below is run...
Set oWshNet = CreateObject("WScript.Network")
sUser = oWshNet.UserName
sComputer = oWshNet.ComputerName
f.Write Now & " User: " & sUser _
& " Computer: " & sComputer & " Status: "
If oFSO.FileExists(sDesktop & "\" & sSC) Then
f.WriteLine "Link " & sSC & " exists"
Else
f.WriteLine "Link " & sSC & " does not exist"
End If
' create registry marker so the script is not run again
oShell.RegWrite "HKCU\Software\LinkTest\Excel", "Done"
' close the file so others are able to continue
f.Close
bUpdFinished = True
End If
Err.Clear
Loop Until bUpdFinished
On Error GoTo 0
My suggestion is always to learn by trying... Logging to a file is something
that you can quickly find by doing a Google search. Here's a modified
version of Torgeir's script to get you started...
' Create the objects needed
Set oShell = CreateObject("WScript.Shell")
Set oNet = CreateObject("WScript.Network")
Set oFSO = CreateObject("Scripting.FileSystemObject")
' Open the file in append mode (8)
Set ts = oFSO.OpenTextFile("\\server\log\log.txt", 8, True)
' Set the shortcut and find the desktop
sSC = "QuickTime Player.lnk"
sDesktop = oShell.SpecialFolders("Desktop")
' Check if the shortcut exists and log the result
If oFSO.FileExists(sDesktop & "\" & sSC) Then
ts.WriteLine oNet.ComputerName & ": Shortcut exists"
Else
ts.WriteLine oNet.ComputerName & ": Shortcut does not exist"
End If
' Close and cleanup
ts.Close
Set ts = Nothing
Set oFSO = Nothing
Set oNet = Nothing
Set oShell = Nothing
My other suggestion is to just ignore my post and look at the much better
script Torgeir posted =).
I modified the script to point to the right shortcut and
it works. No I will try and add a drive mapping to allow
me to do the samething on a remote PC.
Is there a book or resource (besides the forum) you can
recommend to help me learn real world scripting?
Thanks
>.
>
> Thank you Torgeir and Yoann for posting you botrh have
> helped me.
>
> I modified the script to point to the right shortcut and
> it works. No I will try and add a drive mapping to allow
> me to do the samething on a remote PC.
Doing this task against a remote computer needs a totally different approach
really. The script I supplied is supposed to be run by the user on each
computer (from e.g. a logon script).
> Is there a book or resource (besides the forum) you can
> recommend to help me learn real world scripting?
Download WSH 5.6 documentation from here:
http://msdn.microsoft.com/downloads/list/webdev.asp
For more starting points:
as my sig states:
Administration scripting examples and a ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter
Starting e.g. here
Scripting Concepts and Technologies for System Administration
http://www.microsoft.com/technet/scriptcenter/scrguide/sas_pt1_overview.asp
The online version can be bought as a book (with a companion CD),
http://www.amazon.com/exec/obidos/ASIN/0735618674/002-7141687-9862444
Here are some Windows Script Host (WSH) Web introductions:
WSH
http://cis.stvincent.edu/wsh/index.html
Introduction to Windows Scripting
http://www.winguides.com/article.php?id=2
NT Gains Scripting Muscle
An introduction to Windows Script Host by Bob Wells.
http://www.winnetmag.com/Articles/Index.cfm?ArticleID=3026
Scripting 101
A 4 part series on how to create and structure WSH scripts by Bob Wells
http://www.winnetmag.com/Articles/Index.cfm?ArticleID=5410
http://www.winnetmag.com/Articles/Index.cfm?ArticleID=5505
http://www.winnetmag.com/Articles/Index.cfm?ArticleID=5683
http://www.winnetmag.com/Articles/Index.cfm?ArticleID=7112
VBScript Primer
http://www.microsoft.com/technet/prodtechnol/windows2000serv/maintain/optimize/script/netvbscr.asp
If you are looking for AD related scripts, you'll can also check this sites
(the link above to the Script Center also have a lot of AD related scripts):
http://www.rallenhome.com/scripting.html
http://www.rlmueller.net/
Here is a newsgroup thread you should look at as well with links to other
resources:
From: Wayne (n...@spam.com)
Subject: beginner looking for resources
Newsgroups: microsoft.public.scripting.vbscript
Date: 2002-01-31 08:11:00 PST
http://groups.google.com/groups?hl=en&th=7015b808b5fb0cb4
This one is not mentioned in the link above
A lot of example scripts there, as well as a nice cheap VBScript editor (it
doesn't beat PrimalScript, but then again the price difference is quite large).
When talking about editors, an alternative as well is the script editor that
comes with Office 2k/XP:
Both scripts work great.
Here is how I am trying to modify them to look in a remote
users folder(eventually 175 users folders) then disconnect.
I map an administrative share to a computer, but I cannot
find a way to make the script look in the mapped drives
content for the all usrs desktop then take a look for the
icon. It always looks at my desktop. I am logged in as an
adminsitrator.
Sorry for butchering your script;
Const ForAppending = 8
On Error Resume Next
Dim oNet
Set oNet = CreateObject("Wscript.Network")
oNet.MapNetworkDrive "w:", "\\workstation154\c$"
On Error GoTo 0
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
sRegVal = "" ' init value
sRegVal = LCase(oShell.RegRead
("HKCU\Software\LinkTest\Excel"))
On Error GoTo 0
If sRegVal = "done" Then
' user has already run this script, quit
WScript.Quit
End If
sSC = "Ethereal.lnk"
sDesktop = oShell.SpecialFolders("Desktop")
' file to log to
sLogFile = "\\server10\log\log.txt"
If oFSO.FileExists(sDesktop & "\" & sSC) Then
f.WriteLine "Link " & sSC & " exists"
Else
f.WriteLine "Link " & sSC & " does not exist"
End If
' create registry marker so the script is not run again
'oShell.RegWrite "HKCU\Software\LinkTest\Excel", "Done"
' close the file so others are able to continue
f.Close
bUpdFinished = True
End If
Err.Clear
Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemoveNetworkDrive "w:"
> Thank you both for helping me out.
>
> Both scripts work great.
> Here is how I am trying to modify them to look in a remote
> users folder(eventually 175 users folders) then disconnect.
>
> I map an administrative share to a computer, but I cannot
> find a way to make the script look in the mapped drives
> content for the all usrs desktop then take a look for the
> icon. It always looks at my desktop. I am logged in as an
> adminsitrator.
>
> Sorry for butchering your script;
Hi
Here is a different approach needed when doing it remotely (I have assumed that
the path to the users profile folder is "\Documents and Settings", see
variable sProfilePath):
Const ForAppending = 8
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oNet = CreateObject("Wscript.Network")
' file to log To
sLogFile = "\\server10\log\log.txt"
sDriveLetter = "w:"
sSC = "Ethereal.lnk"
sProfilePath = "\Documents and Settings"
sComputer = "workstation154"
' open for appending
Set f = oFSO.OpenTextFile(sLogFile, ForAppending, True)
f.WriteLine vbCrLf & " ******* " & Now _
& " Log for computer " & sComputer & " *******" & vbCrLf
On Error Resume Next
If oFSO.DriveExists(sDriveLetter) Then
oNet.RemoveNetworkDrive
End If
oNet.MapNetworkDrive sDriveLetter, "\\" & sComputer & "\c$"
If Err.Number <> 0 Then
f.WriteLine "Could not map drive to admin share c$"
Else
On Error GoTo 0
Set oFolder = oFSO.GetFolder(sDriveLetter & sProfilePath)
For Each oSubFolder In oFolder.SubFolders
f.Write "User: " & oSubFolder.Name _
& " Computer: " & sComputer & " Status: "
If oFSO.FileExists(oSubFolder.Path & "\Desktop\" & sSC) Then
f.WriteLine "Link " & sSC & " exists"
Else
f.WriteLine "Link " & sSC & " does not exist"
End If
Next
oNet.RemoveNetworkDrive sDriveLetter
End If
f.Close