Search Results

Search found 518 results on 21 pages for 'vbscript'.

Page 3/21 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • How to terminate process using VBScript

    - by Mark
    Hi, I have this VBScript code to terminate one process Const strComputer = "." Dim objWMIService, colProcessList Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'Process.exe'") For Each objProcess in colProcessList objProcess.Terminate() Next it works fine with some processes, but when it comes to any process runs under SYSTEM, it can't stop it. Is there is anything I need to add to kill the process under SYSTEM? Thanks

    Read the article

  • Boolean Not operator in VBScript

    - by Lumi
    Consider the following two conditionals (involving bitwise comparisons) in VBScript: If 1 And 3 Then WScript.Echo "yes" Else WScript.Echo "no" If Not(1 And 3) Then WScript.Echo "yes" Else WScript.Echo "no" Prints first yes, then no, right? cscript not.vbs Wrong! It prints yes twice! Wait a second, the Not operator is supposed to perform logical negation on an expression. The logical negation of true is false, as far as I know. Must I conclude that it doesn't live up to that promise? How and why and what is going on here? What is the rationale, if any?

    Read the article

  • Vbscript - Object Required for DateLastModified

    - by Kenny Bones
    I don't really know what's wrong right here. I'm trying to create a vbscript that basically checks two Folders for their files and compare the DateLastModified attribute of each and then copies the source files to the destination folder if the DateLastModified of the source file is newer than the existing one. I have this code: Dim strSourceFolder, strDestFolder Dim fso, objFolder, colFiles strSourceFolder = "c:\users\user\desktop\Source\" strDestFolder = "c:\users\user\desktop\Dest\" Set fso = CreateObject("Scripting.FileSystemObject") Set objFolder = fso.GetFolder(strSourceFolder) Set colFiles = objFolder.Files For each objFile in colFiles Dim DateModified DateModified = objFile.DateLastModified ReplaceIfNewer objFile, DateModified, strSourceFolder, strDestFolder Next Sub ReplaceIfNewer (sourceFile, DateModified, SourceFolder, DestFolder) Const OVERWRITE_EXISTING = True Dim fso, objFolder, colFiles, sourceFileName, destFileName Dim DestDateModified, objDestFile Set fso = CreateObject("Scripting.FileSystemObject") sourceFileName = fso.GetFileName(sourceFile) destFileName = DestFolder & sourceFileName if fso.FileExists(destFileName) Then objDestFile = fso.GetFile(destFileName) DestDateModified = objDestFile.DateLastModified msgbox "File last modified: " & DateModified msgbox "New file last modified: " & DestDateModified End if End Sub And I get the error: On line 34, Char 3 "Object required: 'objDestFile' But objDestFile IS created?

    Read the article

  • read out a txt and send the last line to email adress - vbscript

    - by matthias
    Hallo, I'm back haha :-) so i have the next question and i hope someone can help me... I know i have a lot of questions but i will try to learn vbscript :-) Situation: I try to make a program that check all 5 min a txt and if there a new line in the txt, i'll try to send it to my eMail Address Option Explicit Dim fso, WshShell, Text, Last, objEmail Const folder = "C:\test.txt" Set fso=CreateObject("Scripting.FileSystemObject") Set WshShell = WScript.CreateObject("WScript.Shell") Do Text = Split(fso.OpenTextFile(Datei, 1).ReadAll, vbCrLF) Letzte = Text(UBound(Text)) Set objEmail = CreateObject("CDO.Message") objEmail.From = "[email protected]" objEmail.To = "[email protected]" objEmail.Subject = "Control" objEmail.Textbody = Last objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _ "smtpip" objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objEmail.Configuration.Fields.Update objEmail.Send WScript.Sleep 300000 Loop This program works, but this program send me all 5 mins a mail...but i will only have a new mail when there is a new line in the txt. Can someone help me?

    Read the article

  • How to Execute an Oracle SQL Statements with VBScript

    - by Arno Conradie
    I am trying to execute an Oracle SQL statement or Oracle Functions through Microsoft VBScript and the loop throught the result set or display the value returned by the function So far I have managed to connect to Oracle via SQLPlus*, but now I am stuck. Can anybody help? Dim output Dim WshShell, oExec, input set WshShell = CreateObject("WScript.Shell") set oEnv=WshShell.Environment("Process") cmdString = "C:\Oracle\11g\product\11.1.0\ruby\BIN\sqlplus.exe -S stradmin/stradmin@ruby select * from dual" Set oExec = WshShell.Exec(cmdString) WScript.Echo "Status" & oExec.Status Do While oExec.Status = 0 WScript.Sleep 2 Loop input = "" Do While Not oExec.StdOut.AtEndOfStream input = input & oExec.StdOut.Read(1) Loop wscript.echo input

    Read the article

  • VBScript: how to set values from recordset to string

    - by phill
    This is probably a beginner question, but how do you set a recordset to a string variable? Here is my code: Function getOffice (strname, uname) strEmail = uname WScript.Echo "email: " & strEmail Dim objRoot : Set objRoot = GetObject("LDAP://RootDSE") Dim objDomain : Set objDomain = GetObject("LDAP://" & objRoot.Get("defaultNamingContext")) Dim cn : Set cn = CreateObject("ADODB.Connection") Dim cmd : Set cmd = CreateObject("ADODB.Command") cn.Provider = "ADsDSOObject" cn.Open "Active Directory Provider" Set cmd.ActiveConnection = cn cmd.CommandText = "SELECT physicalDeliveryOfficeName FROM '" & objDomain.ADsPath & "' WHERE mail='" & strEmail & "'" cmd.Properties("Page Size") = 1 cmd.Properties("Timeout") = 300 cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE Dim objRS : Set objRS = cmd.Execute WScript.Echo objRS.Fields(0) Set cmd = Nothing Set cn = Nothing Set objDomain = Nothing Set objRoot = Nothing Dim arStore Set getOffice = objRS.Fields(0) Set objRS = Nothing End function When I try to run the function, it throws an error "vbscript runtime error: Type mismatch" I presume this means it can't set the string variable with a recordset value. How do I fix this problem?

    Read the article

  • VBScript Permission Denied on CopyFile

    - by Chris
    I'm running a VBScript in SQL Agent but I get a 'Permission Denied' on line 34 (the first copy attempt). I've run this script outside SQL Agent with no problems Function Main() Const SourceDrive As String = "X:\" Dim fso Dim Today Dim FileName Dim FromFile Dim FromDrive Dim ArchivePath Set fso = CreateObject("Scripting.FileSystemObject") Today = Format(Now, "yyyyMMdd") 'To add more sources just add them to the array list Dim Sources() As Variant Sources() = Array("Item1", _ "Item2") 'To add more targets just add them to the array list Dim Targets() As Variant Targets() = Array("C:\Users\myalias\Desktop\MyToFolder", _ "C:\Users\myalias\Desktop\MyToFolder2") For i = 0 To UBound(Sources) FileName = "WebSurveyAlertCallbacks_" & Sources(i) & "_" & Today & ".xls" FromDrive = fso.BuildPath(SourceDrive, Sources(i)) FromFile = fso.BuildPath(FromDrive, FileName) ArchivePath = fso.BuildPath(FromDrive, "Archive") If fso.FileExists(FromFile) Then For t = 0 To UBound(Targets) fso.CopyFile FromFile, fso.BuildPath(Targets(t), FileName), True Next fso.CopyFile FromFile, fso.BuildPath(ArchivePath, FileName), True fso.DeleteFile FromFile End If Next Set fso = Nothing Main = DTSTaskExecResult_Success End Function

    Read the article

  • VBScript - using IF statements in a mail script?

    - by Kenny Bones
    I really need some quick tips here. I've got this VBScript script which sends an e-mail. And I want to do several checks to see if an attribute is true and if it is, write an additional line in the mail. How can I do this? This is part of the script: obMessage.HTMLBody = ""_ & "<MENU>"_ & "<LI type = square>This is a line</i>."_ I want something which looks like this: obMessage.HTMLBody = ""_ & "<MENU>"_ If statement1 = true Then & "<LI type = square>This is an additional line</i>."_ end if Preferrably, could some select statements be made? I don't really mind what the code looks like, I just want it to work as soon as possible :)

    Read the article

  • How to retrieve large data from oracle database using vbscript

    - by allenzzzxd
    Hi guys, I'm now working on vbscript to do some test. Actuelly, I want to retrieve a large amount of data from an oracle database, so I write the code like this: sql = "Select * from CORE_DB where MC = '" & mstr & "' " Set myrs = db_execute_query(curConnection, sql) Then I count the rows in myrs,there are 248 rows. So then I do a For loop to retrieve some fields of each row. For k = 0 To db_get_rows_count(myrs) But then I found that the content of the row k when k 133 was always equal to k = 133. So this makes an error. As I think, there may be a limit size of mrys ? Could anyone light me about this? Thanks a lot in advance

    Read the article

  • VBScript Writing to Server Text File

    - by Keyfer Mathewson
    I have created a VBScript which pulls the service tag, username, and computer name from a computer. What I need to do now is compile this information in a text document. How it's set up is as follows: We have an Active Directory Server, with a folder for login scripts. I have created a batch file to run this .vbs script, and the script works well so far. What I now need is for a file on the AD server, called "logging.txt", to be populated with the information that is created with the .vbs script. This is the script I have so far: 'Get Dell Service Tag Info set ProSet = GetObject("winmgmts:").InstancesOf("Win32_BIOS") Set ProSet1 = GetObject("winmgmts:").InstancesOf("Win32_SystemEnclosure") For each Pro in ProSet For each Pro1 in ProSet1 ServiceTag=Pro.SerialNumber wscript.echo ServiceTag exit for Next exit for Next 'get username and computername, could also be asked in a batch Set oShell = WScript.CreateObject("WScript.Shell") Set oShellEnv = oShell.Environment("Process") sComputerName = oShellEnv("ComputerName") sUsername = oShellEnv("username") wscript.echo sComputerName & " " & sUsername Thank you very much in advance!

    Read the article

  • What's wrong with this regex (VBScript/Javascript flavor)

    - by OtherMichael
    I'm trying to run a regular expression in VBA code that uses Microsoft VBScript Regular Expressions 5.5 (should be the same as JavaScript regex) regex: ^[0-9A-Z]?[0-9A-Z]{3}[A-Z]?([0-9A-Z]{6})-?([0-9])?$ input: X123A1234567 match: 123456 the six characters I'm interested in give a good match of 123456, ignoring the last (check) digit. Perfect. (The check digit is captured, but it's not a major concern to me). But when BOTH the optional portions are gone (they are optional) the match grabs the last digit GOOD input: 123A1234567 match: 123456 Leave in the optional middle alpha, take out the optional leading alpha, and we still get the good match of 123456 GOOD input: X1231234567 match: 123456 Leave in the optional leading alpha, take out the middle optional alpha, and we still get a good match of 123456 BAD input: 1231234567 match: 234567 Take out BOTH optional alphas, and we get a bad match of 234567 Have a looksee @ the regex testers on http://www.regular-expressions.info/javascriptexample.html or http://www.regular-expressions.info/vbscriptexample.html What am I missing, here? How can I get the regex to ignore the last digit when both optional alphas are missing? The regex is used to feed a lookup system, so that no matter what format the input data, we can match to a complete value.

    Read the article

  • Can't write the SysWow64 value to registry with vbscript for Screensaver

    - by Valentein
    Scripts, registries, screen-savers, oh my! I'm trying to use a screen-saver on a Windows XP 64 bit machine which uses a .NET app which makes an interop call which relies on some x86 Shockwave Dlls (some Shockwave animation). Everything should be in the %systemroot%\WINNT\SysWOW64 directory. When the timeout for the screensaver occurs, the process should looks like this: Screensaver.scr - .NET app - shockwave animation. During installation I want a vbscript to my screen-saver file to copy the Screensaver.scr to the SysWow64 directory and then set the proper registry key to this file for Windows to launch the screen-saver. The code is something like this: Dim sScreenSaver, tScreenSaver sScreenSaver = "C:\SourceFiles\bin\ScreenSaver.scr" 'screensaver tScreenSaver = "C:\winnt\SysWOW64\" Set WshShell = WScript.CreateObject("WScript.Shell") 'script shell to run objects Set FSO = createobject("scripting.filesystemobject") 'file system object 'copy screensaver FSO.CopyFile sScreenSaver, tScreenSaver, True 'set screen saver Dim p1 p1 = "HKEY_CURRENT_USER\Control Panel\Desktop\" WshShell.RegWrite p1 & "SCRNSAVE.EXE", (tScreenSaver & "ScreenSaver.scr") After installation, I can verify the the Screensaver exists in the correct directory. (It actually seems to be in both the system32 and the sysWOW64 directories---whether that's the install script or something I did post-install I'm in the process of verifying.) However, the registry entry is not correct. In both the 32 and 64 bit regedit I see the HKCU\ControlPanel\Desktop\SCRNSAVE.EX is set to: C:\WINNT\system32\Screensaver.scr This isn't right. The screen-saver won't run from this directory. It only runs from SysWOW64. If I manually edit the registry with regedit to the correct SysWOW64 path everything works fine. Is this a problem with using the script or is this a Windows registry redirection, or filesystem redirection problem? You'd think this would be simple...

    Read the article

  • VBScript: Disable caching of response from server to HTTP GET URL request

    - by Rob
    I want to turn off the cache used when a URL call to a server is made from VBScript running within an application on a Windows machine. What function/method/object do I use to do this? When the call is made for the first time, my Linux based Apache server returns a response back from the CGI Perl script that it is running. However, subsequent runs of the script seem to be using the same response as for the first time, so the data is being cached somewhere. My server logs confirm that the server is not being called in those subsequent times, only in the first time. This is what I am doing. I am using the following code from within a commercial application (don't wish to mention this application, probably not relevant to my problem): With CreateObject("MSXML2.XMLHTTP") .open "GET", "http://myserver/cgi-bin/nsr/nsr.cgi?aparam=1", False .send nsrresponse =.responseText End With Is there a function/method on the above object to turn off caching, or should I be calling a method/function to turn off the caching on a response object before making the URL? I looked here for a solution: http://msdn.microsoft.com/en-us/library/ms535874(VS.85).aspx - not quite helpful enough. And here: http://www.w3.org/TR/XMLHttpRequest/ - very unfriendly and hard to read. I am also trying to force not using the cache using http header settings and html document header meta data: Snippet of server-side Perl CGI script that returns the response back to the calling client, set expiry to 0. print $httpGetCGIRequest-header( -type = 'text/html', -expires = '+0s', ); Http header settings in response sent back to client: <html><head><meta http-equiv="CACHE-CONTROL" content="NO-CACHE"></head> <body> response message generated from server </body> </html> The above http header and html document head settings haven't worked, hence my question.

    Read the article

  • Copy folder contents using VBScript

    - by LukeR
    I am trying to copy the contents of certain folders to another folder using VBScript. The goal is to enumerate a user's AD groups and then copy specific folder content based on those groups. I have code, which is currently not working. Dim Group,User,objFSO,objFolder,source,target,StrDomain StrDomain = "domain.local" FolderBase = "\\domain.local\netlogon\workgrps\icons" Set net = CreateObject("wscript.network") Struser = net.username target = "\\fs1\users\"&net.username&"\Desktop\AppIcons\" DispUserInWhichGroup() Function DispUserInWhichGroup() On Error Resume Next Set objFSO=CreateObject("Scripting.FileSystemObject") Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user") For Each Group In User.Groups source = FolderBase & Group.name Set objFolder = GetFolder(source) For Each file in objFolder.Files objFSO.CopyFile source &"\"& file.name, target&"\"&file.name Next Next End Function This has been cobbled together from various sources, and I'm sure most of it is right, I just can't get it working completely. Any assistance would be great. Cheers.

    Read the article

  • how to delete multiple folders,desktop and start menu shortcut using vbscript

    - by user1756858
    I never did any vbscript before, so i don't know if my question is very easy one. Following is the flow of steps that has to be done : Check if exist and delete a folder at c:\test1 if found and continue. If not found continue. Check if exist and delete a folder at c:\programfiles\test2 if found and continue. If not found continue. Check if a desktop shortcut and start menu shortcut exist and delete if found. If not exit. I could delete 2 folders with the following code: strPath1 = "C:\test1" strPath1 = "C:\test1" DeleteFolder strPath1 DeleteFolder strPath1 Function DeleteFolder(strFolderPath1) Dim objFSO, objFolder Set objFSO = CreateObject ("Scripting.FileSystemObject") If objFSO.FolderExists(strFolderPath) Then objFSO.DeleteFolder strFolderPath, True End If Set objFSO = Nothing But i need to run one script to delete 2 folders in different paths, 2 shortcuts one in start menu and one on desktop. I was experimenting with this code to delete the shortcut on my desktop: Dim WSHShell, DesktopPath Set WSHShell = WScript.CreateObject("WScript.Shell") DesktopPath = WSHShell.SpecialFolders("Desktop") on error resume next Icon = DesktopPath & "\sample.txt" Set fs = CreateObject("Scripting.FileSystemObject") Set A = fs.GetFile(Icon) A.Delete WScript.Quit It works fine for txt file on desktop, but how do i delete a shortcut for an application from desktop as well as start menu.

    Read the article

  • VBScript and Xpath excluding duplicates [closed]

    - by Malachi
    I am trying to pull names from an XML Document using a vbscript. XML Document structure <Aliases> <Alias PartyType="DF" CaseID="000000" NameType=""> Name Name</Alias> <Alias PartyType="DF" CaseID="000000" NameType=""> Name Name</Alias> <Alias PartyType="DF" CaseID="000000" NameType=""> Name Name</Alias> ... </Aliases> the XML File might have 100 rows with the same name coming from several different CaseID's because for this part of my vbscript I am trying to pull all the different Names from all cases, but here is the issue, I don't want to return duplicates. is there a way to do this with an xPath Expression or should I try to do this with VBScript? EDIT I am pretty sure that I am going to have to do this with VBScript. Would it be Faster and more efficient to solve this issue in VBScript, xPath, or in populating the XML I am retrieving information from ( this might prove more difficult than the other two options ) I am also asking a Similar question on stackoverflow

    Read the article

  • VBScript Multiple folder check if then statement

    - by user2868186
    I had this working before just fine with the exception of getting an error if one of the folders was not there, so I tried to fix it. Searched for a while (as much as I can at work) for a solution and tried different methods, still no luck and my IT tickets are stacking up at work, lol, woohoo. Thanks for any help provided. Getting syntax error on line 60 character 60, thanks again. Option Explicit Dim objFSO, Folder1, Folder2, Folder3, zipFile Dim ShellApp, zip, oFile, CurDate, MacAdd, objWMIService Dim MyTarget, MyHex, MyBinary, i, strComputer, objItem, FormatMAC Dim oShell, oCTF, CurDir, scriptPath, oRegEx, colItems Dim FoldPath1, FoldPath2, FoldPath3, foldPathArray Const FOF_SIMPLEPROGRESS = 256 'Grabs MAC from current machine strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") For Each objItem in colItems MacAdd = objItem.MACAddress Next 'Finds the pattern of a MAC address then changes it for 'file naming purposes. You can change the FormatMAC line of the code 'in parenthesis where the periods are, to whatever you like 'as long as its within the standard file naming convention Set oRegEx = CreateObject("VBScript.RegExp") oRegEx.Pattern = "([\dA-F]{2}).?([\dA-F]{2}).?([\dA-F]" _ & "{2}).?([\dA-F]{2}).?([\dA-F]{2}).?([\dA-F]{2})" FormatMAC = oRegEx.Replace(MacAdd, "$1.$2.$3.$4.$5.$6") 'Gets current date in a format for file naming 'Periods can be replaced with anything that is standard to 'file naming convention CurDate = Month(Date) & "." & Day(Date) & "." & Year(Date) 'Gets path of the directory where the script is being ran from Set objFSO = CreateObject("Scripting.FileSystemObject") scriptPath = Wscript.ScriptFullName Set oFile = objFSO.GetFile(scriptPath) CurDir = objFSO.GetParentFolderName(oFile) 'where and what the zip file will be called/saved MyTarget = CurDir & "\" & "IRAP_LOGS_" & CurDate & "_" & FormatMAC & ".zip" 'Actual creation of the zip file MyHex = Array(80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0) For i = 0 To UBound(MyHex) MyBinary = MyBinary & Chr(MyHex(i)) Next Set oShell = CreateObject("WScript.Shell") Set oCTF = objFSO.CreateTextFile(MyTarget, True) oCTF.Write MyBinary oCTF.Close Set oCTF = Nothing wScript.Sleep(3000) folder1 = True folder2 = True folder3 = True 'Adds folders to the zip file created earlier 'change these folders to whatever is needing to be copied into the zip folder 'Folder1 If not objFSO.FolderExists("C:\Windows\Temp\SMSTSLog") and If not objFSO.FolderExists("X:\Windows\Temp\SMSTSLog") then Folder1 = false End If If objFSO.FolderExists("C:\Windows\Temp\SMSTSLog") Then Folder1 = "C:\Windows\Temp\SMSTSLog" Set FoldPath1 = objFSO.getFolder(Folder1) Else Folder1 = "X:\windows\Temp\SMSTSLog" Set FoldPath1 = objFSO.getFolder(Folder1) End If 'Folder2 If not objFSO.FolderExists("C:\Windows\System32\CCM\Logs") and If not objFSO.FolderExists("X:\Windows\System32\CCM\Logs") then Folder2 = false End If If objFSO.FolderEXists("C:\Windows\System32\CCM\Logs") Then Folder2 = "C:\Windows\System32\CCM\Logs" Set FoldPath2 = objFSO.getFolder(Folder2) Else Folder2 = "X:\Windows\System32\CCM\Logs" Set FoldPath2 = objFSO.getFolder(Folder2) End If 'Folder3 If not objFSO.FolderExists("C:\Windows\SysWOW64\CCM\Logs") and If not objFSO.FolderExists("X:\Windows\SysWOW64\CCM\Logs") then Folder3 = false End If If objFSO.FolderExists("C:\Windows\SysWOW64\CCM\Logs") Then Folder3 = "C:\Windows\SysWOW64\CCM\Logs" set FolderPath3 =objFSO.getFolder(Folder3) Else Folder3 = "X:\Windows\SysWOW64\CCM\Logs" Set FoldPath3 = objFSO.getFolder(Folder3) End If set objFSO = CreateObject("Scripting.FileSystemObject") objFSO.OpenTextFile(MyTarget, 2, True).Write "PK" & Chr(5) & Chr(6) _ & String(18, Chr(0)) Set ShellApp = CreateObject("Shell.Application") Set zip = ShellApp.NameSpace(MyTarget) 'checks if files are there before trying to copy 'otherwise it will error out If folder1 = True And FoldPath1.files.Count >= 1 Then zip.CopyHere Folder1 End If WScript.Sleep 3000 If folder2 = true And FoldPath2.files.Count >= 1 Then zip.CopyHere Folder2 End If WScript.Sleep 3000 If folder3 = true And FoldPath3.files.Count >= 1 Then zip.CopyHere Folder3 End If WScript.Sleep 5000 set ShellApp = Nothing set ZipFile = Nothing Set Folder1 = Nothing Set Folder2 = Nothing Set Folder3 = Nothing createobject("wscript.shell").popup "Zip File Created Successfully", 3

    Read the article

  • Calling WCF service with parameters from VBScript

    - by Mick Mason
    http://stackoverflow.com/questions/944975 I'm trying to use the code from the above stack article, but my WCF service method requires parameters: SaveCheckData int,int,string,string I've tried frigging with the code to incorporate this, but to be honest, I may as well be trying to perform heart surgery. Can anyone shed any light on how i'd need to modify the code to call a SOAPAction that requires parameters? Thanks Mick

    Read the article

  • Vbscript - Checking each subfolder for files and copy files

    - by Kenny Bones
    I'm trying to get this script to work. It's basically supposed to mirror two sets of folders and make sure they are exactly the same. If a folder is missing, the folder and it's content should be copied. Then the script should compare the DateModified attribute and only copy the files if the source file is newer than the destination file. I'm trying to get together a script that does exactly that. And so far I've been able to check all subfolder if they exist and then create them if they don't. Then I've been able to scan the top source folder for it's files and copy them if they don't exist or if the DateModified attribute is newer on the source file. What remains is basically scanning each subfolder for its files and copy them if they don't exist or if the DateModified stamp is newer. Here's the code: Dim strSourceFolder, strDestFolder strSourceFolder = "c:\users\vegsan\desktop\Source\" strDestFolder = "c:\users\vegsan\desktop\Dest\" Set fso = CreateObject("Scripting.FileSystemObject") Set objTopFolder = fso.GetFolder(strSourceFolder) Set colTopFiles = objTopFolder.Files 'Check to see if subfolders actually exist. Create if they don't Set objColFolders = objTopFolder.SubFolders For Each subFolder in objColFolders CheckFolder subFolder, strSourceFolder, strDestFolder Next ' Check all files in first top folder For Each objFile in colTopFiles CheckFiles objFile, strSourceFolder, strDestFolder Next Sub CheckFolder (strSubFolder, strSourceFolder, strDestFolder) Set fso = CreateObject("Scripting.FileSystemObject") Dim folderName, aSplit aSplit = Split (strSubFolder, "\") UBound (aSplit) If UBound (aSplit) > 1 Then folderName = aSplit(UBound(aSplit)) folderName = strDestFolder & folderName End if If Not fso.FolderExists(folderName) Then fso.CreateFolder(folderName) End if End Sub Sub CheckFiles (file, SourceFolder, DestFolder) Set fso = CreateObject("Scripting.FileSystemObject") Dim DateModified DateModified = file.DateLastModified ReplaceIfNewer file, DateMofidied, SourceFolder, DestFolder End Sub Sub ReplaceIfNewer (sourceFile, DateModified, SourceFolder, DestFolder) Const OVERWRITE_EXISTING = True Dim fso, objFolder, colFiles, sourceFileName, destFileName Dim DestDateModified, objDestFile Set fso = CreateObject("Scripting.FileSystemObject") sourceFileName = fso.GetFileName(sourceFile) destFileName = DestFolder & sourceFileName if Not fso.FileExists(destFileName) Then fso.CopyFile sourceFile, destFileName End if if fso.FileExists(destFileName) Then Set objDestFile = fso.GetFile(destFileName) DestDateModified = objDestFile.DateLastModified if DateModified <> DestDateModified Then fso.CopyFile sourceFile, destFileName End if End if End Sub

    Read the article

  • VBScript Out of String space

    - by MalsiaPro
    I got the following code to capture information for files on a specified drive, I ran the script againts a 600 GB hard drive on one of our servers and after a while I get the error Out of String space; "Join". Line 34, Char 2 For this code, file script.vbs: Option Explicit Dim objFS, objFld Dim objArgs Dim strFolder, strDestFile, blnRecursiveSearch ''Dim strLines Dim strCsv ''Dim i '' i = 0 ' 'Get the commandline parameters ' Set objArgs = WScript.Arguments ' strFolder = objArgs(0) ' strDestFile = objArgs(1) ' blnRecursiveSearch = objArgs(2) '######################################## 'SPECIFY THE DRIVE YOU WANT TO SCAN BELOW '######################################## strFolder = "C:\" strDestFile = "C:\InformationOutput.csv" blnRecursiveSearch = True 'Create the FileSystemObject Set objFS=CreateObject("Scripting.FileSystemObject") 'Get the directory you are working in Set objFld = objFS.GetFolder(strFolder) 'Open the csv file Set strCsv = objFS.CreateTextFile(strDestFile, True) '' 'Write the csv file '' Set strCsv = objFS.CreateTextFile(strDestFile, True) strCsv.WriteLine "File Path,File Size,Date Created,Date Last Modified,Date Last Accessed" '' strCsv.Write Join(strLines, vbCrLf) 'Now get the file details GetFileDetails objFld, blnRecursiveSearch '' 'Close and cleanup objects '' strCsv.Close '' 'Write the csv file '' Set strCsv = objFS.CreateTextFile(strDestFile, True) '' For i = 0 to UBound(strLines) '' strCsv.WriteLine strLines(i) '' Next 'Close and cleanup objects strCsv.Close Set strCsv = Nothing Set objFld = Nothing Set strFolder = Nothing Set objArgs = Nothing '---------------------------SCAN SPECIFIED LOCATION------------------------------- Private Sub GetFileDetails(fold, blnRecursive) Dim fld, fil dim strLine(4) on error resume next If InStr(fold.Path, "System Volume Information") < 1 Then If blnRecursive Then 'Work through all the folders and subfolders For Each fld In fold.SubFolders GetFileDetails fld, True If err.number <> 0 then LogError err.Description & vbcrlf & "Folder - " & fold.Path err.Clear End If Next End If 'Now work on the files For Each fil in fold.Files strLine(0) = fil.Path strLine(1) = fil.Size strLine(2) = fil.DateCreated strLine(3) = fil.DateLastModified strLine(4) = fil.DateLastAccessed strCsv.WriteLine Join(strLine, ",") if err.number <> 0 then LogError err.Description & vbcrlf & "Folder - " & fold.Path & vbcrlf & "File - " & fil.Name err.Clear End If Next End If end sub Private sub LogError(strError) dim strErr 'Write the csv file Set strErr = objFS.CreateTextFile("C:\test\err.log", false) strErr.WriteLine strError strErr.Close Set strErr = nothing End Sub RunMe.cmd wscript.exe "C:\temp\script\script.vbs" How can I avoid getting this error? The server drives are quite a bit <???? and I would imagine that the CSV file would be at least 40 MB. Edit by Guffa: I commented out some lines in the code, using double ticks ('') so you can see where.

    Read the article

  • ASP/VBScript ServerXmlHttp Encoding

    - by colinramsay
    I'm pulling an RSS feed from a remote location using ServerXmlHttp: Dim httpRequest set httpRequest = server.createObject("Msxml2.ServerXMLHTTP.6.0") httpRequest.open "GET", "http://www.someurl.com/feed.xml", false httpRequest.send() response.write httpRequest.responseXML.xml However there must be encoding issues somewhere along the line as I'm seeing ???? where there should be some Japanese characters. Does anyone have any guidance when working with ServerXmlHttp? Thanks.

    Read the article

  • Find Users E-Mail via SID using VBScript and Active Directory

    - by er4z0r
    Hi, I am parsing log messages about changes to user accounts on a windows system. I want to notify the user about the changes so I need to retrieve their personal information (First,Last, E-Mail) from Active Directory. I already found a way to retrieve the username but that is only via WMI and not ADSI: Function FindUser(Message) Dim objWMIService Dim strAccountRegex Dim objRegex Dim objMatch Dim strComputer Dim objUser Dim objShell strAccountRegex = "(\%\{[A-Z,0-9,\-]*\})" strComputer = "." Wscript.StdOut.writeLine "Querying WMI to retrieve user-data" Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set objShell = WScript.CreateObject("WScript.Shell") Set objRegex = new RegExp objRegex.Pattern= strAccountRegex for each objMatch in objRegex.Execute(Message) REM Wscript.StdOut.writeLine "Found an Account ID: " & objMatch.value Dim strSID strSID=NormalizeSID(objMatch.value) REM Wscript.Echo "SID after escaping: " & strSID Set objUser = objWMIService.Get _ ("Win32_SID.SID='" & strSID & "'") next FindUser=objUser.ReferencedDomainName & "\" & objUser.AccountName End Function It works fine, but I would like to do it via Active Directory instead of going via WMI. Can you help me?

    Read the article

  • VBScript Regular Expressions to check IP address validity with some adtional characters

    - by yael
    How to create VB script Irregular expression syntax to check the VPparam (IP address validity) When the last octatat of the IP address is a range between ip's (x-y) and between each IP we can put the "," separator in order to add another IP example of VBparam VBparam=172.17.202.1-20 VBparam=172.17.202.1-10,192.9.200.1-100 VBparam=172.17.202.1-10,192.9.200.1-100,180.1.1.1-20 THX yael

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >