KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Remote Shutdown

 
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive
View previous topic :: View next topic  
Author Message
frak
KiXforms Dabbler
KiXforms Dabbler


Joined: 14 Mar 2003
Posts: 6
Location: Manchester UK

PostPosted: Fri Apr 25, 2003 1:44 pm    Post subject: Remote Shutdown Reply with quote

Hi all,
Here is a little app i was working on at a customer site, unfortunately i have not been able to test it too extensively as i they won't let me go around shutting down their machines left right and centre. The code is not the most elegant or efficient in the world so feel free to make changes. The script is based on Jens and Shawn's Netview2 function and the kixtart shutdown command. I know there is a resource kit tool to do this but it was more an experiment in learning kixforms than anything else. Anyway if it's rubbish feel free to delete it lol. Sorry can't upload a screen shot at mo.

frak

Code:

;* Script to shut down remote machines
;* frak 25/04/2003
;* Requires Kixtart 4.x, Kixforms 2.3.0.38
break on
$domain = @domain
$wait_value = 0

$Form = CreateObject("Kixtart.Form")         ;create the form
$Form.Caption = "Server & Workstation Shutdown"      ;window caption
$Form.Width = 420               ;size
$Form.Height = 500               ;size
$Form.center   

$Frame1 = $Form.Frame("Machine Options",20,55,175,350)
$Frame2 = $Form.Frame("Shut Down Options",215,55,175,350)

$label1 = $Form.Label("Domain Name :- $domain",40,75,120,25)
$list1  = $Form.Listbox(,40,105,140,225)

$cmd1 = $Form.CommandButton("Change &Domain",40,350)
$cmd1.onclick = "onbuttonclick()"

$OptionButton1 = $Form.OptionButton("Reboot",250,105,75,20)
$OptionButton1.checked =1

$OptionButton2 = $Form.OptionButton("Shut Down",250,140,75,20)

$label2 = $Form.Label("Seconds to wait",250,240,80,20)
$Text1 = $Form.Textbox(0,250,270,50,20)

$cmd2 = $Form.CommandButton("&Shut Down",250,350)
$cmd2.onclick = "onbutton2click()"

for each $computer in netview2($domain)
              $list1.additem($computer)
              next


$cmd3 = $Form.CommandButton("E&xit",290,430)
$cmd3.onclick = "onbutton3click()"


$Form.Show

While $Form.Visible
  $=Execute($Form.DoEvents())
Loop

FUNCTION onbuttonclick
$domain = $Form.Inputbox("input domain name","Change Domain",$domain)
$list1.clear
$label1.text = "Domain Name :- $domain"
for each $computer in netview2($domain)
              $list1.additem($computer)
              next
ENDFUNCTION

FUNCTION onbutton2click
$wait_value = $text1.text
$selection = $form.msgbox("Are you sure you want to Shut down this Machine","Warning",4)
   If $selection = 6
      IF $OptionButton1.checked = 1
      shutdown($list1.text,"closing",$wait_value,1,1)
      ENDIF
      IF $OptionButton2.checked = 1
      Shutdown($list1.text,"closing",$wait_value,1,0)
      ENDIF
   ENDIF
ENDFUNCTIOn


FUNCTION onbutton3click
quit
endfunction

;FUNCTION      NetView2()
;
;AUTHOR        Jens Meyer (sealeopard@usa.net), Shawn
;
;ACTION        Enumerate all announced computers in your domain
;
;VERSION       1.1
;
;SYNTAX        NetView2([Domain,Comment])
;
;PARAMETERS    DOMAIN
;              Specifies the domain to enumerate. If domain is omitted, returns a
;              list of all announced computers in the current domain.
;
;              COMMENT
;              Optional boolean to determine whether to return the associated computer
;              comment (separated by a comma from the computername)
;
;RETURNS       An array of strings representing all the computers in the domain
;
;REMARKS       This UDF returns a list of computers that are PINGable. Computers, that
;              are members of the domain but are currently not connected to the domain,
;              will not be listed. For a list of joined computers independent of whether
;              they are on- or off-line use COMNetView().
;
;              Slightly improved version of Shawn's NetView() UDF
;              at http://81.17.37.55/cgi-bin/ultimatebb.cgi?ubb=print_topic;f=12;t=000059
;
;DEPENDENCIES  none
;
;EXAMPLE       for each $computer in netview2()
;                ? ''+$computer
;              next
;
;KIXTART BBS   http://81.17.37.55/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=12;t=000202
;
function NetView2(optional $domain, optional $commentflag)
  dim $array[255]
  dim $redim, $i, $j, $tempfile
  dim $filehandle, $retcode
  dim $name, $comment

  $redim = 255
  $i = 0
  $j = 0
  $tempfile = '%temp%\netview.tmp'

  if $domain
    $domain = '/domain:'+trim($domain)
  endif

  if vartype($commentflag)
    $commentflag=val($commentflag)
  else
    $commentflag=0
  endif

  if exist($tempfile)
    del $tempfile
  endif

  shell '%comspec% /c net view $domain >"'+$tempfile+'"'

  if @error = 0
    $filehandle=1
    do
      $retcode=open($filehandle,$tempfile)
      $filehandle=$filehandle+1
    until $retcode=0 or $filehandle=11
    select
    case $retcode=-3
      exit 4
    case $retcode=-2
      exit 6
    case $retcode=-1
      exit 123
    case $retcode=0
      $filehandle=$filehandle-1
    case $retcode>0
      exit @ERROR
    case $filehandle=11
      exit 4
    endselect

    for $j = 1 to 5
      $line = readline($filehandle) ; skip headings
    next

    while @error = 0
      $name= trim(substr($line,3,instr($line,' ')-1))
      $comment = trim(right($line,len($line)-instr($line,' ')))
      if $commentflag
        $array[$i]=$name+','+$comment
      else
        $array[$i]=$name
      endif
      $i=$i+1
      if $i = $redim
        $redim=$redim*2
        redim preserve $array[$redim]
      endif
      $line = readline($filehandle)
    loop
    $retcode=close($filehandle)
    del $tempfile
    if $i
      redim preserve $array[$i-4]
      $netview2 = $array
      exit @error
    endif
  endif

  $netview2 = 0
  exit @error
endfunction
Back to top
View user's profile Send private message MSN Messenger
frak
KiXforms Dabbler
KiXforms Dabbler


Joined: 14 Mar 2003
Posts: 6
Location: Manchester UK

PostPosted: Fri Apr 25, 2003 1:46 pm    Post subject: Doh! Reply with quote

I just realised that cross domain shutdown probably doesnt work, cant be sure but i suspect it doesnt will have to test that when i get home, if it doesnt it renders half the script useless.
Still the script is nice for scheduling reboots of those troublesome servers at 4 in the morning

frak
Back to top
View user's profile Send private message MSN Messenger
masken
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 14 Mar 2003
Posts: 202
Location: Gothenburg, Sweden

PostPosted: Wed Apr 30, 2003 1:16 pm    Post subject: Reply with quote

Very slick m8, works like a charm! Smile
Back to top
View user's profile Send private message MSN Messenger
frak
KiXforms Dabbler
KiXforms Dabbler


Joined: 14 Mar 2003
Posts: 6
Location: Manchester UK

PostPosted: Thu May 01, 2003 4:24 pm    Post subject: Reply with quote

Thanks for the feedback Very Happy
Did you try cross domain shutdown ? and if so did it work ?
I've been busy and not had a chance to look at it since. With the bank holiday weekend coming up i am hoping to come up with a few more ideas for kixforms apps but glad you like this one. What do you think of the form layout ? i know i should be using groups boxes now but i am more interested in what people think of the layout of the form. I am useless at design on the whole which is why i have never had a web page lol. So what do you think guys ?

frak
Back to top
View user's profile Send private message MSN Messenger
masken
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 14 Mar 2003
Posts: 202
Location: Gothenburg, Sweden

PostPosted: Sat May 03, 2003 11:36 pm    Post subject: Reply with quote

I couldn't test it across domains, as I only have one domain here Wink

The GUI is pretty good. Perhaps some sort of progress meter, or initial graphic could be made, so initialization begins before the computer list is compiled, cause I have around 170 machines on my domain, and it took some time before anything at all showed up Wink
Back to top
View user's profile Send private message MSN Messenger
krabourn
KiXforms Aficionado
KiXforms Aficionado


Joined: 05 Mar 2003
Posts: 273
Location: San Antonio. TX

PostPosted: Sun May 04, 2003 12:32 am    Post subject: Reply with quote

The import thing is what kind of rights do you have on the workstation. It is not so much that the computer is on another domain. In my programs I check to make sure I have admin rights before issueing the shutdown or whatever command. There are probably about 10 domains that are in my immediate area or responsiblity. I know I dont have domain Admin or workstation admin rights in all those domains.

The main thing is, If the person running this has the correct rights on the remote computer, it will work.

I hope that rambling helped.

_________________
Kelly
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Mon May 05, 2003 11:14 am    Post subject: Reply with quote

mm...
wonder...
if the force would be an option and reboot too.
and both worked with checkboxes...
could get the code even shorter Wink

_________________
Hammer
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Dean F
KiXforms Dabbler
KiXforms Dabbler


Joined: 19 May 2003
Posts: 13
Location: Seattle

PostPosted: Mon May 19, 2003 10:24 pm    Post subject: Cross Domain - Workgroup to Domain info Reply with quote

I really like this. Quite nice.

Just an FYI-

I tried it from a Win XP laptop which was not a member of a domain and it was automatically able to enumerate all active servers. It did not, however, let me shutdown or reboot a server which I have administrative permissions on, but I suspect that it somehow grabbed my standard user credentials instead of my admin user credentials (XP caches credentials if you want). I'll have to go back and give it another try.

Thanks,

-Dean F.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group