Sign in to follow this  
Followers 0
jcchipper

remote process running

4 posts in this topic

Hi. This is my first post here so allow me to briefly introduce myself. I'm a SA for a network, which comprises 8 servers 82 workstations over 250 users. I have worked in the field for a little over 5 years. For the most part my responsibilities our outlined to: Trouble shooting software problems, OS problems, Server problems to include services/programs like: AD,DNS,DHCP,IIS,Exchange,ISA,Security,ETC. My tasking have recently shifted over time to include coding. While I have stuck more or less to using scripting technologies as little as possible, however I have found their usefulness to invaluable. As such I have begun to study how scripting languages work.

Where I work I am not expected to understand the inter workings of how programs work. I am just expected to understand how they work and fix them if they break. If it turns into a problem, which involves code, I resort to turning the problem over to the source. Problem with this is that most scripting technologies require a more advanced understanding of how software works/hardware. IE. What process it calls a dll fileor whatever the case may be. Plus it helps drastically when trouble shooting software problems. So my studies currently have taken me more into the lines of programming.

I am extremely new to writing scripts. I mostly work with WMI/VB scripts. Using both of these to administer either to computer projects or active directory projects. I am still trying to get a clear understanding of each intricate part works. Here is why I bring this up:

I have been working on a project for about a month, which provides the automation, and anti breaking of automated maintenance. While I have gotten almost all functions to perform exactly the way I want them to there is one function that I cannot seem to get to work properly.

Break down of my automation project:

Every night a 1am the LAN system shuts itself down to perform maintenance. I use AD to perform the maintenance via script. This is script number 2. Script number 1 is used to activate script 2. Script 2 functions the way I want it to. Script 1 works but just not the way I want it to.

Here is the parts of script 1 which are not functioning the way I want it to:

This part of the script calls another script which function is to display a timer then restart the computer as soon as the timer expiers.

-------------Creates remote restart computer with a gui timer restart--------------------------------------------

-------------Simplify a break down of my problem call this piece of the larger script script 1-------------------

-------------Note that the progressbarshutdown.exe code is right below----------------------

$SW_NORMAL = 1
$s_Machine = $var
$s_Command = "C:\AdminTools\Shutdown\progressbarshutdown.exe"
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
$objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate,(Shutdown)}!\\" & $s_Machine & "\root\cimv2")

$objStartup = $objWMIService.Get("Win32_ProcessStartup")
$objConfig = $objStartup.SpawnInstance_
$objConfig.ShowWindow = $SW_NORMAL

$objProcess = $objWMIService.Get("Win32_Process")
$intReturn = $objProcess.Create _
    ($s_Command)

This part starts a timer then restarts the computer AKA progressbarshutdown.exe

------------------Gui timer/Restart of computer----------------------------------------

-------------Simplify a break down of my problem call this piece of the larger script script 2-------------------

-------------This installed on all machine's and is initiated at the local computer via the top script---------------

#Include <Constants.au3>
Dim $colItems, $i, $objItem, $objWMIService, $s_Command
Dim $s_Machine, $wbemFlagReturnImmediately, $wbemFlagForwardOnly

ProgressOn("Progress Meter", "Time till restart PC", "60 seconds")
For $i = 60 to 1 step -1
    sleep(1000)
    ProgressSet( Int(($i/60)*100), $i & " seconds")
Next
ProgressSet(100 , "Done", "Complete")
sleep(500)
ProgressOff()

$s_Machine = "LocalHost"
$s_Command = 6

;$s_Command=6 can also use the values of: 
; 0=Log Off|0+4=Forced Log Off|1=Shutdown|1+4=Forced Shutdown|2=Reboot|2+4=Forced Reboot|8=Power Off|8+4=Forced Power Off|1+8=Shutdown/Power Off|1+4+8=Forced shutdown/Power Off

    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate,(Shutdown)}!\\" & $s_Machine & "\root\cimv2")
    $colItems = $objWMIService.ExecQuery("SELECT * From Win32_OperatingSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    For $objItem in $colItems
        $objItem.Win32Shutdown($s_Command)
    Next

Both scripts run fine with no errors. In fact they function just fine. The problem that I have is that I cannot for the life of me get the gui to display when I remote initiate the second script. Script 1 creates a run process on the remote target, which activates script 2. Script 2 then runs. I can see that the timer function is performed it even restarts the target, however the part that doesn't work is that there is no gui. I don't know if I have write something else to ensure the gui displays or what. I know the code functions. If I locally click on the .exe it displays the gui timer and restarts. Remotely run though it does not create the gui it does run the timer function and restarts the computer.

I've been running through any resource that I can find to possible find what the problem is....let alone if there is a problem. If it helps I can post the complete code for this project...but I do not believe it will help might only confuse more people. As they try to make sense of the code I wrote. Being that I am new I am using methods that I understand which are probably making script's 100x longer than they need to be. Let alone there is a lot more functionality that I want to add in which is far from being even close to development.

The idea once this project is completed that I will have two programs. One that controls computer maintenance automation, a second one that controls reboot of a remote computer. I know that there are many utilities that exist that perform the functions that I am doing with the scripts that I am designing. The only thing is that I didn't create them. Microsoft has its shutdown.exe, which can be used to locally/remotely reboot a terminal. There are other utilities, which have the ability to run a process on a remote computer much like I just did.

However the problem is that they have to exist. While I can use utilities from Microsoft I am not authorized to use utilities from other locations unless they under go a great deal of testing to prove they will not attempt any unauthorized activities beyond what they are designed to do. I apologies for the length of this post as well as for the lack of documentation in the above scripts. I have yet to add any of that in. Thanks for looking at this.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I use PSEXEC to run a program remotely. It has an option to run visible or invisible to the user.

A quick search on the Internet returned lots of hits like this:

You cannot open a process on the interactive desktop with WinMgmt.

The ability to create an interactive process remotely was a bug fixed in

W2K-SP3,

and it is not availalbe by design in WinXP and W2K3.

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

i'm working on wmi and remote processes

WMI will always not show the gui on remote process, because of security (imagine a user that can interact with an application that you have launched under admin)


-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites

Thank you for the replies. Didn't dawn on me that gui type interface's wouldn't be able to execute remotely like this. Certainly can understand why they aren't allowed now that I looked deeper into the mater. To bypass this problem to a degree I switched to remote task scheduling. This though has only proved to be a temporary solution as this form of execution can interact with the user the way I wanted it to. Yet cannot interact with the system should no user account be logged in.

Code that I used to complete this tasking is listed below. If anyone has a solution to launch a gui type interface on a non-logged in computer I would be open to suggestion's. JdeB thank you for your suggestion yet it does not provide me with a solution to a non-logged in computer.

$strComputer = $var
$strCommand  = "C:\AdminTools\Shutdown\progressbarshutdown.exe"
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20

$objWMIService = ObjGet("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) 
For $objItem in $colItems 
    $dtmLocalTime = $objItem.LocalDateTime
    $dtmMonth = "**"
    $dtmDay = "**"
    $dtmYear = "****"
    $dtmHour = StringMid($dtmLocalTime, 9, 2)
    $dtmMinutes = StringMid($dtmLocalTime, 11, 2)
    $dtmSeconds = StringMid($dtmLocalTime, 13, 2)
Next

$objSWbemServices = ObjGet("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$colTimeZone = $objSWbemServices.ExecQuery _
 ("SELECT * FROM Win32_TimeZone", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
For $objTimeZone in $colTimeZone
 $strBias = $objTimeZone.Bias
Next

$dtmMinutes = $dtmMinutes + 1

$dtmNewDate = $dtmMonth & $dtmDay & $dtmYear
$dtmNewTime =  $dtmHour & $dtmMinutes & "00"

$scheduletasktime = $dtmNewDate & $dtmNewTime & ".000000" & $strBias

$objWMIService = ObjGet("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$objitem = $objWMIService.Get("Win32_ScheduledJob")
$errRTN = $objitem.Create _
($strCommand, $scheduletasktime, "FALSE", "", "", "True")

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0