?
Solved

VBS script need to replace server name with logonserver

Posted on 2005-04-14
3
Medium Priority
?
826 Views
Last Modified: 2012-06-27
Hi guys please can you help me out here, I have a script that copies a file to the pc's system32 directory but I am having difficulty, I would like to set the %netlogon% as the source folder.

at the moment is errors saying "source folder not found" however I replace the source folder with a UNC server name and path it all works fine. I am in a desperate hurry for this so I have put 500 points on it, I would put 10,000 if I could thanks in advanced !!!

'==========================================================================
dim strSource, strDestination
strSource = "\\wfflongham01\netlogon\logo\"
strDestination = "c:\windows\system32\logo\"
'==========================================================================

SynchroniseFiles strSource, strDestination

function SynchroniseFiles(byval strSourceFolder, byval strDestinationFolder)

     CheckForBackSlash strSourceFolder
     CheckForBackSlash strDestinationFolder
     
     dim objFSO
     set objFSO = Createobject("scripting.filesystemobject")
     
     if not objFSO.folderexists(strDestinationFolder) then
          objFSO.createfolder(strDestinationFolder)
     end if

     dim file
     for each file in objFSO.getfolder(strSourceFolder).files
     
          if not objFSO.fileexists(strDestinationFolder & file.name) then
               objFSO.copyfile file, strDestinationFolder & file.name
          else
               if file.DateLastModified > objFSO.getfile(strDestinationFolder & file.name).DateLastModified then
                    objFSO.copyfile file, strDestinationFolder & file.name
               end if
          end if
     next

     set objFSO = nothing

end function


function CheckForBackSlash(byref strFolder)
     if right(strFolder, 1) <> "\" then
          strFolder = strFolder & "\"
     end if
end function
0
Comment
Question by:Blackduke77
1 Comment
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 13788824
This will put the environment variable %Logonserver% into the script variable "Logonserver":

dim wsh
set wsh = WScript.CreateObject ("WScript.Shell")
LogonServer = wsh.ExpandEnvironmentStrings("%LogonServer%")
WScript.Echo "Logonserver is " & Logonserver
Set wsh = Nothing

So you can modify the beginning of your script like that:

'==========================================================================
dim wsh
set wsh = WScript.CreateObject ("WScript.Shell")
LogonServer = wsh.ExpandEnvironmentStrings("%LogonServer%")
Set wsh = Nothing

dim strSource, strDestination
strSource = Logonserver & "\netlogon\logo\"
strDestination = "c:\windows\system32\logo\"
'==========================================================================

Windows Script Host: ExpandEnvironmentStrings Method
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthexpandenvironmentstrings.asp
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is in response to a question (http://www.experts-exchange.com/Networking/Network_Management/Network_Analysis/Q_28230497.html) here at Experts Exchange. The Original Poster (OP) requires a utility that will accept a list of IP addresses …
This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question