« Posts under General Tools

Philips Zymed Holter Configuration File v2.9.4 Backup Script

Being the sole IT support person for Philips Zymed where I am employed I sometimes get calls about a configuration that the reader has changed and is unable to restore to their original settings.  Being an IT individual, I am not well versed in all of the Holter tools and functions.  So I did some research to determine where the Holter application configuration information was stored. I wrote a script that I placed in the startup folder on the PC to backup the Holter configuration files every time a reader logs on to the system.  When I receive a call with a configuration issue, all I have to do is restore my backed up files.  These backup configuration files have a date/time stamp attached which allows me multiple configuration files I can restore from.  See DOS BATCH script below:

@echo off
setlocal
CLS

echo Holter Configuration File Backup (v100a)
echo (c) 2011 Your Company Here (08/29/2011)
echo. 

REM
REM Break Date and Time down into managable pieces
REM
call :SETTIMEVARS

REM
REM Set some environment variables for easy alterations later.
REM
set USRCFGPATH=%APPDATA%\Holter
set USRBKUPPATH=%APPDATA%\Holter\Backup
set APPCFGPATH=%ALLUSERSPROFILE%\Application Data\Holter
set APPBKUPPATH=%ALLUSERSPROFILE%\Application Data\Holter\Backup

REM
REM Copy the User Configuration Files to the Backup Folder and time stamp the files.
REM
mkdir "%USRBKUPPATH%" > NUL: 2>&1
copy /v "%USRCFGPATH%\CentralUsrConfig.ini" "%USRBKUPPATH%\CentralUsrConfig.ini.%CCTIME%"
copy /v "%USRCFGPATH%\HolterUsrConfig.ini" "%USRBKUPPATH%\HolterUsrConfig.ini.%CCTIME%"
copy /v "%USRCFGPATH%\RemoteUsrConfig.ini" "%USRBKUPPATH%\RemoteUsrConfig.ini.%CCTIME%"

REM
REM Copy the App Configuration Files to the Backup Folder and time stamp the files.
REM
mkdir "%APPBKUPPATH%" > NUL: 2>&1
copy /v "%APPCFGPATH%\CentralAppConfig.ini" "%APPBKUPPATH%\CentralAppConfig.ini.%CCTIME%"
copy /v "%APPCFGPATH%\HolterAppConfig.ini" "%APPBKUPPATH%\HolterAppConfig.ini.%CCTIME%"
copy /v "%APPCFGPATH%\RemoteAppConfig.ini" "%APPBKUPPATH%\RemoteAppConfig.ini.%CCTIME%"

goto FIN

:SETTIMEVARS
  for /f "tokens=1* delims= " %%a in ('date/t') do set dayname=%%a
  for /f "tokens=2* delims= " %%a in ('date/t') do set mmddyyyy=%%a
  for /f "tokens=1* delims=/" %%a in ('echo %mmddyyyy%') do set month=%%a
  for /f "tokens=2* delims=/" %%a in ('echo %mmddyyyy%') do set day=%%a
  for /f "tokens=3* delims=/" %%a in ('echo %mmddyyyy%') do set year=%%a
  for /f "tokens=1* delims=:" %%a in ('echo %time%') do set hour=%%a
  for /f "tokens=2* delims=:" %%a in ('echo %time%') do set mins=%%a
  for /f "tokens=3* delims=:" %%a in ('echo %time%') do set sec=%%a
  for /f "tokens=1* delims=." %%a in ('echo %sec%') do set secs=%%a
  for /f "tokens=2* delims=." %%a in ('echo %sec%') do set mili=%%a
  if %hour% lss 10 set hour=0%hour%

  REM create an environment variable which includes date time stamp.
  set CCTIME=%year%%month%%day%_%hour%%mins%%secs%
GOTO :EOF

:FIN
endlocal
Exit

Retrieve Desktop Shortcut (URL and LNK) Information Remotely

Every needed to get all of the TargetPaths and Parameters from the Shortcuts and URLs from a remote machine (given you have the permissions)? This script below will gather all of that information display it to the console and save the same link information into a file called links.txt on your C:\ drive. The script will scour each and ever user folder under C:\Documents and Settings\. This script will work successfully on Windows XP machines, it will not however work on Windows Vista or Windows 7 due to the location of the users folders.

Usage:
cscript links.vbs
cscript links.vbs

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set filetxt = objFSO.OpenTextFile("c:\links.txt", ForAppending, True)
set oArgs=wscript.Arguments

Function Ping(myHostName)

   Dim colPingResults, objPingResult, strQuery

   strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & myHostName & "'"

   Set colPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery( strQuery )

   For Each objPingResult In colPingResults
      If Not IsObject( objPingResult ) Then
        Ping = False
      ElseIf objPingResult.StatusCode = 0 Then
        Ping = True
      Else
        Ping = False
      End If
   Next

   Set colPingResults = Nothing

End Function

Sub forceUseCScript()
   If Not WScript.FullName = WScript.Path & "\cscript.exe" Then
      objShell.Run "cmd.exe /c " & WScript.Path & "\cscript.exe //NOLOGO " & _
         Chr(34) & WScript.scriptFullName & Chr(34) & " " & oArgs(0),1,False
      WScript.Quit 0
   End If
End Sub 

Sub QueryLNKURL(Path)
   Set objFolder = objFSO.GetFolder(Path)
   For each objFile in objFolder.Files
      strPath = objFile.Path
      Select Case Right(Lcase(objFile),4)
         Case ".lnk":
            Set objShortcut = objShell.CreateShortcut(strPath)
            netPath = "\\" & oArgs(0) & "\c$"
            Temp = Replace(objShortcut.FullName, netPath, "C:")
            filetxt.WriteLine(oArgs(0) & "|L|" & Temp & "|" & _
               objShortcut.TargetPath & "|" & objShortcut.Arguments)
            Wscript.Echo oArgs(0) & "|L|" & Temp & "|" & objShortcut.TargetPath & _
               "|" & objShortcut.Arguments
         Case ".url":
            Set objShortcut = objShell.CreateShortcut(strPath)
            netPath = "\\" & oArgs(0) & "\c$"
            Temp = Replace(objShortcut.FullName, netPath, "C:")
            filetxt.WriteLine(oArgs(0) & "|U|" & Temp & "|" & objShortcut.TargetPath)
            Wscript.Echo oArgs(0) & "|U|" & Temp & "|" & objShortcut.TargetPath
      End Select
   Next

   For each objFile in objFolder.SubFolders
      strPath = objFile.Path
      QueryLNKURL(strPath)
   Next

End Sub

Sub RecurseFolderDesktop(sDir)
   Set oDir = objFSO.GetFolder(sDir)
   For Each i In oDir.SubFolders
      if ((strcomp(i.Name, "Default User", 1) <> 0) and _
          (strcomp(i.Name, "LocalService", 1) <> 0) and _
          (strcomp(i.Name, "NetworkService", 1) <> 0) and _
          (strcomp(i.Name, "Administrator", 1) <> 0)) then
         if (objFSO.FolderExists(sDir & "\" & i.Name & "\Desktop")) then
            QueryLNKURL(sDir & "\" & i.Name & "\Desktop")
         end if
      end if
   Next
End Sub

Banner = "Links v100a " & chr(13) & chr(10) & "(c)2011 Your Site" & _
         chr(13) & chr(10) & chr(13) & chr(10)

if (oArgs.Count <> 1) then
   Wscript.Echo Banner & chr(13) & chr(10) & _
      "Links Usage: " & chr(13) & chr(10) & "  Links <ip or hostname>"
   Wscript.Quit
end if

forceUseCScript
Wscript.Echo Banner

pResult = Ping(oArgs(0))
if pResult = False then
   Temp = "Unable to ping machine.  Invalid IP address or PC not available."
   filetxt.WriteLine(oArgs(0) & "|X|" & Temp & "|")
   Wscript.Echo oArgs(0) & "|X|" & Temp & "|"
else
   ' We have shortcuts in this path on most machines.
   attempt = false
   SCPath = "\\" & oArgs(0) & _
      "\c$\documents and settings\all users\start menu\applications\"
   if (objFSO.FolderExists(SCPath)) then
      QueryLNKURL(SCPath)
      attempt = true
   end if

   SCPath = "\\" & oArgs(0) & "\c$\documents and settings"
   if (objFSO.FolderExists(SCPath)) then
      attempt = true
      RecurseFolderDesktop objFSO.GetFolder(SCPath).Path
   end if

   if (attempt = false) then
      Temp = "Unable to locate any appropriate folders to query."
      filetxt.WriteLine(oArgs(0) & "|X|" & Temp & "|")
      Wscript.Echo oArgs(0) & "|X|" & Temp & "|"
   end if
end if

Set objFolder = Nothing
Set objFSO    = Nothing
Set objShell  = Nothing
filetxt.Close

Add an Active Directory printer VBScript

The area that I support one day needed multiple Active Directory (AD) printers mapped for multiple users on multiple machines.  I wanted a nice uniform way to add all these printers quickly without bothering the end user.  The VBScript that I wrote was placed in the “All Users” startup folder and will be executed by each user automatically when they log on to the system. By placing all the printer mappings in a file I can easily manage adding, deleting, and setting default printers remotely for a user or for all users on that PC. Please see the script and the corresponding data file below.


Option Explicit
CONST ForReading = 1

Dim ComputerName, UserName, objShell, objNetwork, PrinterMapFile, objFSO, strData
Dim pComputer, pUser, pPrinter, pAction, CharacterCount, arrLines, strLine
Dim posn1, posn2, posn3

Set objNetwork = CreateObject("WScript.Network")
Set objShell = WScript.CreateObject("WScript.Shell")

Sub forceUseCScript()
  If Not WScript.FullName = WScript.Path & "\cscript.exe" Then
    objShell.Run "cmd.exe /c " & WScript.Path & "\cscript.exe //NOLOGO " & Chr(34) & _
    WScript.scriptFullName & Chr(34),1,False
    WScript.Quit 0
  End If
End Sub

forceUseCScript

' Get the computer's name.
ComputerName = UCase(objNetwork.ComputerName)
UserName = UCASE(objShell.ExpandEnvironmentStrings("%USERNAME%"))

Wscript.Echo "Printer Mapper v100a"
Wscript.Echo "Company Name Here"
Wscript.Echo " "

'name of the text file
PrinterMapFile = "C:\printer.map"

'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Check to see if File Exists, if not then exit right there.
If NOT objFSO.FileExists(PrinterMapFile) then
  wscript.quit
end if

'Open the text file - strData now contains the whole file
strData = objFSO.OpenTextFile(PrinterMapFile,ForReading).ReadAll

'Split the text file into lines
arrLines = Split(strData,vbCrLf)

'Step through the lines
For Each strLine in arrLines
  CharacterCount = Len(strLine) - Len(Replace(strLine, ",", ""))
  if Left(strLine, 1) <> "'" and CharacterCount = 3 then
    posn1 = InStr(1, strLine, ",", 1)
    posn2 = InStr(posn1+1, strLine, ",", 1)
    posn3 = InStr(posn2+1, strLine, ",", 1)
    pComputer = UCase(Left(strLine, posn1-1))
    pUser = UCase(Mid(strLine, posn1+1, posn2-posn1-1))
    pPrinter = Mid(strLine, posn2+1, posn3-posn2-1)
    pAction = Right(strLine, Len(strLine) - posn3)

    if pComputer = ComputerName then
      if pUser = UserName or pUser = "ALLUSERS" then
        ' Add and make it default
        if pAction = "D" then
          Wscript.Echo "Adding/Default: " & pPrinter
          objNetwork.AddWindowsPrinterConnection pPrinter
          objNetwork.SetDefaultPrinter pPrinter
        end if

        ' Add
        if pAction = "A" then
          Wscript.Echo "Adding: " & pPrinter
          objNetwork.AddWindowsPrinterConnection pPrinter
        end if

        ' Remove
        if pAction = "R" then
          Wscript.Echo "Removing: " & pPrinter
          objNetwork.RemovePrinterConnection pPrinter
        end if
      end if
    end if
  end if
Next

'Cleanup
Set objFSO = Nothing

<—-Data File—->

' Computer Name,User,PRINTSVR Printer,A(dd), D(efault)/Add, R(emove)
E-CARD-STAFF1,ALLUSERS,\\PRINTSVR\E-EL-COLOR1-PS,A
E-CARD-STAFF2,ALLUSERS,\\PRINTSVR\E-EL-COLOR1-PS,A
E-CARD-STAFF3,ALLUSERS,\\PRINTSVR\E-EL-COLOR1-PS,A
E-CARD-STAFF4,ALLUSERS,\\PRINTSVR\E-EL-COLOR1-PS,A
E-CARD-STAFFMGR,ALLUSERS,\\PRINTSVR\E-EL-COLOR1-PS,D
E-CARD-STAFF5,MRH001,\\PRINTSVR\E-CARD-MFD-PS,A

<—-Data File—->