Jump to content

JohnRichard

Active Members
  • Posts

    188
  • Joined

  • Last visited

JohnRichard's Achievements

Prodigy

Prodigy (4/7)

0

Reputation

  1. Hi JohnOne. I managed to make it working without this error checking you advise. Thanks anyway... Cheers...
  2. Hi JohnOne, I've done that. This line of script will list if PC has Microsoft Document Writer and Microsoft XPS installed in PC.... $var = RegEnumKey("\\10.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers", $i) Then on the Select Case, If the script match the registry name of the printer, it will delete the value... The first select case works fine... Select Case $var = "Microsoft Office Document Image Writer" ;$read = RegRead("\\10.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Microsoft Office Document Image Writer", "Name") RegDelete("\\12.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Microsoft Office Document Image Writer") but the second select case, it failed to delete Case $var = "Microsoft XPS Document Writer" RegDelete("\\12.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Microsoft XPS Document Writer") I wonder why the second case is not being executed....
  3. good day to all. i am trying to make a script which will delete Microsoft Office Document Image Writer and Microsoft XPS Document Writer printer installed to all PC's in our network. i will initiate a registry delete of the entry of the printers. my test script works fine on the first registry part but the second case, it will fail to delete. can someone help me why the script don't work as what i need to. thanks... below is my script For $i= 1 to 10 $var = RegEnumKey("\\12.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers", $i) If @error <> 0 then ExitLoop ;MsgBox(4096, "SubKey #" & $i & " under HKLM\Software: ", $var) Select Case $var = "Microsoft Office Document Image Writer" ;$read = RegRead("\\10.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Microsoft Office Document Image Writer", "Name") RegDelete("\\12.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Microsoft Office Document Image Writer") Case $var = "Microsoft XPS Document Writer" ; $read = RegRead("\\10.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Microsoft XPS Document Writer", "Name") RegDelete("\\12.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Microsoft XPS Document Writer") EndSelect Next ShellExecute("sc.exe", "\\12.110.1.12 stop SPOOLER", @SystemDir) ShellExecute("sc.exe", "\\12.110.1.12 start SPOOLER", @SystemDir)
  4. hi melba...i've just use _FileCountLines just for my testing. sorry i forgot to remove that lines... actually i've played around this script... For $x = $aRecords[0] To 1 Step -1 but i have not think of using the command Step -1. thanks for a great explanation....this is additional knowledge for me using the AutoIT.
  5. hi smartee. it works great. i have not think of using this Step command. thanks
  6. hello guys. i need advise/help on your expertise. i'm kinda stuck on my script. i have this text log on which each records will append after the last line as seen on my sample text file. i wanted that the last entry up to the first entry on the text file will be displayed as first up to the records. i started with my script but is displays from the first entry down to the last entry. i wanted it the other way. i have this script but i'm stuck... this first script works fine. it displays from first to the last entry from the log file... #include <file.au3> Dim $aRecords If Not _FileReadToArray(@DesktopDir & "\log.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf $CountLines = _FileCountLines(@DesktopDir & "\log.txt") MsgBox(64, "Error log recordcount", "There are " & $CountLines & " in the error.log.") For $x = 1 to $aRecords[0] Msgbox(0,'Record:' & $x, $aRecords[$x]) Next I've stuck on this script and will display only the last entry from the text file. #include <file.au3> Dim $aRecords If Not _FileReadToArray(@DesktopDir & "\log.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf $CountLines = _FileCountLines(@DesktopDir & "\log.txt") MsgBox(64, "Error log recordcount", "There are " & $CountLines & " in the error.log.") For $x = $CountLines to $aRecords[0] Msgbox(0,'Record:' & $x, $aRecords[$x]) Nextlog.txt
  7. hi autobert. thanks for the reply. great script and this works. i have the almost similar script which sorts as well. the entry into my text log is that it appends and goes into the last line. i wanted the listview to display the last line up to the first line from the text log which i am having trouble displaying it. i thought i will be able to do that using the register_sort_callback. i have attached the textlog. log.txt
  8. hi wakillon. thanks for the tip. i'll give it a try.
  9. Good day to all AutoIT users. I'm having problem how to arrange the listview items. I'm trying to sort it by date. It can be sorted by using the Function WM_NOTIFY available here on the site. But is sorts the listview by numbers like 1, 10, 2, 20. I wanted to be sorted from the latest list to the oldest. The list comes from a notepad something like the one below. Is this possible? 15/06/2009|2:34:41 PM|2:34:41 PM|00:00:01| PC1 |10.110.5.21 16/06/2009|2:43:15 PM|2:43:18 PM|00:00:03| PC2 |10.110.5.22 21/06/2009|2:44:05 PM|2:44:09 PM|00:00:04| PC3 |10.110.5.23 30/06/2009|2:50:50 PM|2:50:51 PM|00:00:01| PC4 |10.110.5.24 01/07/2009|2:52:50 PM|2:53:26 PM|00:00:35| PC5 |10.110.5.25 10/07/2009|2:54:42 PM|2:55:08 PM|00:00:25| PC6 |10.110.5.26
  10. I am trying to calculate integer then rounded for 1000. I wanted to insert comma (,) after every thousands. Like Round(8300000/1000, 0) will give me 8300. However i would like the result to be like 8,300. How will i do that. I am trying to do _StringInsert function but could not get it working. Here is my sample script. Can someone share their expertise on this one? Thanks... #include<string.au3> $a = Round(8300000/1000, 0) & " KB" For $i = $a/1000 to $a _StringInsert($a, ",", $i) Msgbox (0, "", $a) Next
  11. Thanks. I remember before it is something like then
  12. Hi. I am trying to create a remote task manager like using the WMI query. I am successful on getting list of running processes on remote PC with its Process ID, priority, user and executable path of the process. However what i am trying to get is the CPU usage and Memory usage of each corresponding process just like Windows task Manager. I am returning 0 values on my CPU and Memory usage field. Can somebody help me on this? Is this possible? Here is my script and i am stuck on how to get the CPU and Memory usage. #Include <Constants.au3> #include <GuiTreeView.au3> #Include <GuiListView.au3> #include <Array.au3> #include <File.au3> #Include <GuiTab.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GuiEdit.au3> #include <File.au3> #include <GUIListBox.au3> #include <TabConstants.au3> #include <Misc.au3> Opt("WinTitleMatchMode", 2) Opt("TrayIconHide", 1) Global Const $Cursor_ARROW = 2 Global Const $wbemFlagReturnImmediately = 0x10 Global Const $wbemFlagForwardOnly = 0x20 $gui = GUICreate("Process List", 400, 350, -1, -1) $host = GUICtrlCreateInput("Please enter computer name here...", 22, 30) $end = GUICtrlCreateButton("End Process", 22, 300) $Process = GUICtrlCreateTabItem("Processes") $processes = GUICtrlCreateButton("Show Process", 22, 68, 90, 27) $label = GUICtrlCreateLabel("", 130, 75, 250, 25) $labelcount = GUICtrlCreateLabel("", 20, 115, 280, 25) $listview = GUICtrlCreateListView("", 22, 135, 355, 126, BitOR($LVS_SORTASCENDING, $LVS_SINGLESEL)) _GUICtrlListView_AddColumn ($listview, "Process Name", 120) _GUICtrlListView_AddColumn ($listview, "Username", 100) _GUICtrlListView_AddColumn ($listview, "Process ID", 150) _GUICtrlListView_AddColumn ($listview, "Priority", 120) _GUICtrlListView_AddColumn ($listview, "Executable Path", 180) _GUICtrlListView_AddColumn ($listview, "Command Parameters", 100) _GUICtrlListView_AddColumn ($listview, "CPU Usage", 100) _GUICtrlListView_AddColumn ($listview, "Memory Usage", 100) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit EndIf If $msg = $processes Then _GUICtrlListView_DeleteAllItems($listview ) GUICtrlSetData($label, "Getting list of running process on the computer....") $Process = _Process() $count = _GUICtrlListView_GetItemCount($listview) GUICtrlSetData($label, "") GUICtrlSetData($labelcount, "There are currently " & $count & " running processe(s) on computer.") EndIf If $msg = $end Then $msg = MsgBox(36, "Terminate Process", "Are you sure you want to terminate the process?") If $msg = 6 Then EndProcess() EndIf EndIf Wend Func _Process() Local $sUserName, $sUserDomain Dim $Process[1][8], $i = 1 $strComputer = GUICtrlRead($host) $ping = Ping($strComputer) If $ping Then $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems ReDim $Process[UBound($Process) + 1][8] $Process[$i][0] = $objItem.Name If $objItem.GetOwner($sUserName, $sUserDomain) = 0 Then $Process[$i][1] = $sUserDomain & "\" & $sUserName $Process[$i][2] = $objItem.ProcessId $Process[$i][3] = $objItem.Priority $Process[$i][4] = $objItem.ExecutablePath $Process[$i][5] = $objItem.CommandLine If $objItem.GetOwner($sUserName, $sUserDomain) = 0 Then $Process[$i][5] = $sUserDomain & "\" & $sUserName $i += 1 Next $Process[0][0] = UBound($Process) - 1 If $Process[0][0] < 1 Then SetError(1, 1, 0) EndIf Else SetError(1, 2, 0) EndIf Local $oRefresher = ObjCreate("WbemScripting.SWbemRefresher") $colItems = $oRefresher.AddEnum ($objWMIService, "Win32_PerfFormattedData_PerfProc_Process" ).objectSet $oRefresher.Refresh ; Time delay before calling refresher Local $iTime = TimerInit() Do Sleep(10) Until TimerDiff($iTime) > 100 $oRefresher.Refresh ; Get data For $objItem In $colItems ; Find it in the array For $n = 1 To $Process[0][0] If $Process[$n][1] = $objItem.IDProcess Then $Process[$n][6] = $objItem.PercentProcessorTime $Process[$n][7] = $objItem.WorkingSet ExitLoop EndIf Next Next Else SetError(1) ; Error connecting to WMI EndIf For $i = 1 To UBound($Process) - 1 $tmp = $Process[$i][0] & "|" & $Process[$i][1] & "|" & $Process[$i][2] & "|" & $Process[$i][3] & "|" & $Process[$i][4] _ & "|" & $Process[$i][5] & "|" & $Process[$i][6] & "|" & Round($Process[$i][7] / 1024, 0) & " KB|" GUICtrlCreateListViewItem($tmp, $listview) Next ;EndIf EndFunc Func EndProcess() $string = _GUICtrlListView_GetItemTextArray($listview, -1) For $i = 1 To 1 $PC = GUICtrlRead($host) $param = "\\" & $PC & " " $process = $string[$i] & " -t" $execute = $param & $process $Run = Run("pskill.exe " & $execute, @SystemDir,@SW_HIDE) Sleep(1500) _GUICtrlListView_DeleteItemsSelected($listview) $count = _GUICtrlListView_GetItemCount($listview) MsgBox(64, "Process", $string[$i] & " has been terminated.") Next MsgBox(64, "", "There are currently " & $count & " running processes") EndFunc
  13. Hi to all. I forgot how to use code tag when posting the script. Can somebody remind me of it? Thank you...
  14. wow that's amazing stefan. i have not think of re-writing it with the Filewriteline. Thanks stefan. Cheers!
  15. Hi to all AUTOSCRIPT users. I am writing a script which saves log file in system directory. The log file will contains IP address of the PC. I wanted to delete some entries on the text file when it reaches a certain count. Like if it reached 20 entries, it will delete the first 10 entries and keep the remaining 10 entries. Is this possible in AUTOIT? I have script like this: Dim $aRecords $CountLines = _FileCountLines(@SystemDir & "\pclog.txt") If Not _FileReadToArray(@SystemDir & "\pclog.txt", $aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf If $CountLines > 20 Then For $i = 1 to $aRecords[0] ;Msgbox(0,'Record:' & $i, $aRecords[$i]) ;DELETE FIRST 10 ENTRY IN THE LOG FILE - i am stuck on this Next EndIf Appreciate any of your help. Thank you.
×
×
  • Create New...