Script Example: Fault Reporting

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Script Example: Fault Reporting

Post by CyberCitizen » Tue Jun 04, 2013 1:43 am

Hey Guys,

Here is another small sample script, nothing to flashy, just used to pull some basic information from a computer & present me a text field to type data & save it to my network machine.

I am currently working in a desktop support background & what I find is people start to remember you and get you to fix things while you were out and about. I would always forget to record these to load into our incident management system & would then be asked why other jobs took longer than they should. Basically when I fix something for someone now, I just connect to a remote share I have on my computer & run the application.

It gets the username, then checks it against Active Directory to retrieve the full name, also gets the machine name & the system boot time, usefully for those jobs where the user claims they rebooted the machine. It also has a text field where I can type what work I did on the machine. When I submit it, it saves the information to a text file on that same remote share, so when I get back to my computer I have all the information I need to raise & close a job.

Image

Code: Select all

// COMPILE_OPTS|C:\Temp\IR\SAH Incident Reporting v1.1.exe|M:\Icons\default_document.ico|CONSOLE=0|INCLUDES=1| /NOSYSTRAY /HIDE /LOGFILE=\dev\nul|RUNTIMES=1|BMPS=1
Let>MSG_HEIGHT=320
Let>MSG_WIDTH=500
Let>MSG_STAYONTOP=1
Let>MSG_CENTERED=1
Let>COMMA=,
ExtractFileName>Command_Line,strFileName
ExtractFileExt>Command_Line,strExt
StringReplace>%strFileName%,",,strFileName
StringReplace>%strExt%,",,strExt
StringReplace>%strFileName%,%strExt%,,strFileName
Trim>%strFileName%,strFileName
Let>APP_TITLE=%strFileName%

Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 97
  HelpContext = 5000
  BorderIcons = [biSystemMenu, biMinimize]
  BorderStyle = bsSingle
  Caption = 'SAH Incident Reporting'
  ClientHeight = 257
  ClientWidth = 418
  Color = clBtnFace
  Font.Charset = ANSI_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Courier New'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = False
  OnTaskBar = True
  PixelsPerInch = 96
  TextHeight = 14
  object Label1: TLabel
    Left = 8
    Top = 8
    Width = 154
    Height = 14
    Caption = 'SAH Incident Reporting'
  end
  object Label2: TLabel
    Left = 8
    Top = 32
    Width = 28
    Height = 14
    Caption = 'Name'
  end
  object Label3: TLabel
    Left = 8
    Top = 80
    Width = 56
    Height = 14
    Caption = 'Username'
  end
  object Label4: TLabel
    Left = 216
    Top = 32
    Width = 84
    Height = 14
    Caption = 'Machine Name'
  end
  object Label5: TLabel
    Left = 216
    Top = 80
    Width = 98
    Height = 14
    Caption = 'Machine Uptime'
  end
  object Label6: TLabel
    Left = 8
    Top = 128
    Width = 35
    Height = 14
    Caption = 'Notes'
  end
  object NameField: TEdit
    Left = 8
    Top = 48
    Width = 193
    Height = 22
    TabOrder = 0
  end
  object UsernameField: TEdit
    Left = 8
    Top = 96
    Width = 193
    Height = 22
    TabOrder = 1
  end
  object MachineNameField: TEdit
    Left = 216
    Top = 48
    Width = 193
    Height = 22
    TabOrder = 2
  end
  object MachineUpField: TEdit
    Left = 216
    Top = 96
    Width = 193
    Height = 22
    TabOrder = 3
  end
  object NotesField: tMSMemo
    Left = 8
    Top = 144
    Width = 337
    Height = 105
    WordWrap = True
    ScrollBars = ssVertical
    ScrollBarsAutoShowing = ssVertical
    TabOrder = 4
  end
  object SaveBTN: tMSButton
    Left = 352
    Top = 144
    Width = 59
    Height = 25
    Caption = 'Save'
    Default = True
    TabOrder = 5
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object ExitBTN: tMSButton
    Left = 352
    Top = 184
    Width = 59
    Height = 25
    Caption = 'Exit'
    ModalResult = 2
    TabOrder = 6
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object ClearBTN: tMSButton
    Left = 352
    Top = 224
    Width = 59
    Height = 25
    Caption = 'Clear'
    TabOrder = 7
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,SaveBTN,OnClick,SaveDetails
AddDialogHandler>Dialog1,ClearBTN,OnClick,ClearDetails
AddDialogHandler>Dialog1,ExitBTN,OnClick,Exit
SetDialogProperty>Dialog1,Label1,Caption,%APP_TITLE%
SetDialogProperty>Dialog1,,Caption,%APP_TITLE%
SetDialogProperty>Dialog1,UsernameField,Text,%USER_NAME%
SetDialogProperty>Dialog1,MachineNameField,Text,%COMPUTER_NAME%
SetDialogProperty>Dialog1,NameField,Text,LOADING
SetDialogProperty>Dialog1,MachineUpField,Text,LOADING
SetDialogProperty>Dialog1,NameField,Enabled,False
SetDialogProperty>Dialog1,MachineUpField,Enabled,False
SetDialogObjectFocus>Dialog1,NotesField

Show>Dialog1

//Get Username Results
  Label>GetFullname
  Let>RP_WAIT=1
  Let>RP_WINDOWMODE=0
  Run>cmd /c net user /domain %USER_NAME% | Find "Full Name" > %TEMP_DIR%FullNameOutput.txt
  Wait>0.1
  IfFileExists>%TEMP_DIR%FullNameOutput.txt
    ReadLn>%TEMP_DIR%FullNameOutput.txt,1,FullnameResults
    If>%FullnameResults%=##EOF##
      Let>FullnameResults=N/A
    Else
    EndIf
    StringReplace>%FullnameResults%,    ,,FullnameResults
    StringReplace>%FullnameResults%,   ,,FullnameResults
    StringReplace>%FullnameResults%,  ,,FullnameResults
    StringReplace>%FullnameResults%,%COMMA%,%COMMA% ,FullnameResults
    StringReplace>%FullnameResults%,  , ,FullnameResults
    StringReplace>%FullnameResults%,Full Name,,FullnameResults
    StringReplace>%FullnameResults%,1,,FullnameResults
    StringReplace>%FullnameResults%,2,,FullnameResults
    StringReplace>%FullnameResults%,3,,FullnameResults
    StringReplace>%FullnameResults%,4,,FullnameResults
    StringReplace>%FullnameResults%,5,,FullnameResults
    StringReplace>%FullnameResults%,6,,FullnameResults
    StringReplace>%FullnameResults%,7,,FullnameResults
    StringReplace>%FullnameResults%,8,,FullnameResults
    StringReplace>%FullnameResults%,9,,FullnameResults
    StringReplace>%FullnameResults%,0,,FullnameResults
    DeleteFile>%TEMP_DIR%FullNameOutput.txt
    SetDialogProperty>Dialog1,NameField,Text,%FullnameResults%
    SetDialogProperty>Dialog1,NameField,Enabled,True
  Else
    Wait>0.1
    Goto>GetFullname
  EndIf

//Get Uptime

//Gets Boot Time
Label>GetUpTime
Let>RP_WAIT=1
Let>RP_WINDOWMODE=0
Run Program>cmd /c net stats srv | find "Statistics since" > "%TEMP_DIR%SysTime.txt"
Wait>0.1
IfFileExists>%TEMP_DIR%SysTime.txt
  ReadLn>%TEMP_DIR%SysTime.txt,1,SysBootTime
  StringReplace>%SysBootTime%,Statistics since ,,SysBootTime
  DeleteFile>%TEMP_DIR%SysTime.txt
  SetDialogProperty>Dialog1,MachineUpField,Text,%SysBootTime%
  SetDialogProperty>Dialog1,MachineUpField,Enabled,True
Else
  Wait>0.1
  Goto>GetUpTime
EndIf

Repeat>Timer
  Wait>0.02
Until>Timer

SRT>SaveDetails
  GetDialogProperty>Dialog1,NameField,Text,DialogNameResult
  GetDialogProperty>Dialog1,UsernameField,Text,DialogUsernameResult
  GetDialogProperty>Dialog1,MachineNameField,Text,DialogMachineNameResult
  GetDialogProperty>Dialog1,MachineUpField,Text,DialogMachineUpResult
  GetDialogProperty>Dialog1,NotesField,Text,DialogNotesResult
  DeleteFile>%SCRIPT_DIR%\%DialogMachineNameResult%.%DialogUsernameResult%.txt
  WriteLn>%SCRIPT_DIR%\%DialogMachineNameResult%.%DialogUsernameResult%.txt,WriteResult,Name:		%DialogNameResult%
  WriteLn>%SCRIPT_DIR%\%DialogMachineNameResult%.%DialogUsernameResult%.txt,WriteResult,Username:	%DialogUsernameResult%
  WriteLn>%SCRIPT_DIR%\%DialogMachineNameResult%.%DialogUsernameResult%.txt,WriteResult,Machine:	%DialogMachineNameResult%
  WriteLn>%SCRIPT_DIR%\%DialogMachineNameResult%.%DialogUsernameResult%.txt,WriteResult,Uptime:		%DialogMachineUpResult%%CRLF%
  WriteLn>%SCRIPT_DIR%\%DialogMachineNameResult%.%DialogUsernameResult%.txt,WriteResult,Notes
  WriteLn>%SCRIPT_DIR%\%DialogMachineNameResult%.%DialogUsernameResult%.txt,WriteResult,==========================
  WriteLn>%SCRIPT_DIR%\%DialogMachineNameResult%.%DialogUsernameResult%.txt,WriteResult,%DialogNotesResult%
  MDL>Details Saved To %SCRIPT_DIR%\%DialogMachineNameResult%.%DialogUsernameResult%.txt%CRLF%%CRLF%Name:		%DialogNameResult%%CRLF%Username:	%DialogUsernameResult%%CRLF%Machine:		%DialogMachineNameResult%%CRLF%Uptime:		%DialogMachineUpResult%%CRLF%%CRLF%Notes%CRLF%================================%CRLF%%DialogNotesResult%
END>SaveDetails

SRT>ClearDetails
  Ask>Are You Sure You Want To Clear All Fields?,AskClear
  SetDialogProperty>Dialog1,UsernameField,Text,
  SetDialogProperty>Dialog1,NameField,Text,
  SetDialogProperty>Dialog1,MachineNameField,Text,
  SetDialogProperty>Dialog1,MachineUpField,Text,
  SetDialogProperty>Dialog1,NotesField,Text,
END>ClearDetails

SRT>Exit
  DeleteFile>%TEMP_DIR%FullNameOutput.txt
  DeleteFile>%TEMP_DIR%SysTime.txt
  Exit>0
END>Exit
FIREFIGHTER

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Jun 05, 2013 3:28 am

also gets...& the system boot time, usefully for those jobs where the user claims they rebooted the machine
And useful to know when the virus they downloaded rebooted the machine. Just kidding... sort of.

Very well thought out. I may borrow this one. I understand the problem you face. You walk into a room for one problem and walk out having worked for an hour on five other computers.

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Wed Jun 05, 2013 6:10 am

JRL wrote:Very well thought out. I may borrow this one. I understand the problem you face. You walk into a room for one problem and walk out having worked for an hour on five other computers.
Thanks, that is exactly that, go to fix one, end up fixing 5 & no records of it. At least this allows me to get some information so I can stick it in our record system. Could even have MS monitor the folder & create a job for me if required, however not needed at this stage, and most likely useless for others as well.
FIREFIGHTER

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts