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

JoinAD KiXform script to move computers into an AD

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


Joined: 05 Mar 2003
Posts: 77
Location: Mouse Country

PostPosted: Fri May 30, 2003 1:20 am    Post subject: JoinAD KiXform script to move computers into an AD Reply with quote

This script is a KiXforms script created to help desktop support
people to Move computers into the Active Directory under a specific
OU container.

You can easily modify the OU paths to your specific Network requirements to use in your environment.

Requirements to run this script:
1. Active Directory (can run script for testing without AD)
2. KiXtart v4.x (preferred v4.21)
3. KiXforms v2.3.0 Beta 2 http://www.kixforms.com/assets/index.htm
4. NETDOM.EXE from Microsoft

NOTE NETDOM does not support NT 4 well for moving to
a specific OU in Active Directory

Description of Netdom.exe Syntax and Versions
http://support.microsoft.com/default.aspx?scid=kb;en-us;329721

Obtaining the NETDOM.EXE utility from Microsoft
The document - Best Practices: Active Directory Forest Recovery
Download the documentation archive which contains the NETDOM.EXE utility for 2000
file version 5.2.3687.0 (Friday, September 27, 2002, 8:38:06 PM)
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=3EDA5A79-C99B-4DF9-823C-933FEBA08CFE

Here is a screen shot of how it currently looks




Code:
; *** File Name:    frmJoinAD.kix
; *** Date Created: 2003-05-22 15:00 PST - By Ron Lewis
; *** Comments:   This script is used to MOVE 2000/XP Workstations into an
; *** Active Directory

; *************** REVISION HISTORY  ***************
; 01.02 *** 2003-05-29 15:30 PST - By Ron Lewis
;   Enabled check for blank computer name
; 01.01 *** 2003-05-22 16:55 PST - By Ron Lewis
;   Updated to install and run from UNC batch call
; 01.00 *** 2003-05-22 15:00 PST - By Ron Lewis
;   Original Release

Break On
DIM $nul
IF @PRODUCTTYPE="Windows XP Professional" OR @PRODUCTTYPE="Windows 2000 Professional"
    IF LocalAdmin
      IF EXIST('%WINDIR%\SYSTEM32\KIXFORMS.DLL')
        SHELL '%COMSPEC% /C %WINDIR%\SYSTEM32\regsvr32.exe %WINDIR%\SYSTEM32\KIXFORMS.DLL /U /S'
        DEL('%WINDIR%\SYSTEM32\KIXFORMS.DLL')
      ENDIF
      COPY '@SCRIPTDIR\kixforms.dll' '%WINDIR%\SYSTEM32\'
      SLEEP 2
      SHELL '%COMSPEC% /C %WINDIR%\SYSTEM32\regsvr32.exe %WINDIR%\SYSTEM32\KIXFORMS.DLL /S'
   
    $ScriptVersion=" v1.0"
    $Form = CreateObject("Kixtart.Form")
    $Form.Text = "Move Computer into Active Directory"
    $Form.FontName = "Tahoma"
    $Form.FontSize = 10
    $Form.ClientSize = 640,480  ;370,380
    $Form.BackColor = &E5A88A
    $Form.FontName = "Arial"
    $Form.FontSize = 8
    $Form.Icon = "%WINDIR%\System32\shell32.dll;48"
   
    $ImageList = $Form.ImageList
    $ImageList.ImageSize = 32,32
    $ImageList.Images.Add($Form.SmallImageList.Images(12))
    $ImageList.Images.Add($Form.SmallImageList.Images(9))
   
    $FrameBanner            = $Form.PictureBox
    $FrameBanner.BackColor  = $Form.RGB(138,168,229)
    $FrameBanner.Height     = 70
    $FrameBanner.Left       = 440
    $FrameBanner.Top        = 0
    $FrameBanner.Width      = 70
    $FrameBanner.BorderStyle= 0
   
   
    $PictureBanner          = $FrameBanner.Image
    $PictureBanner.Picture  = "%WINDIR%\System32\shell32.dll;14"
    $PictureBanner.Height   = 60
    $PictureBanner.Left     = 2
    $PictureBanner.Top      = 2
    $PictureBanner.Width    = 60
   
   
    $Form.FillStyle = 1
    $Form.FillColor = &B24801
    $Form.Rectangle(0,0,440,$Form.ClientHeight-20)
    $Form.ForeColor = &E5A88A+&151515
    $Form.FontBold = True
    $Form.FontSize = 10
   
    $Form.PrintXY(5,10,"Computer:")
    $Form.PrintXY(5,60,"Domain\UserID:")
    $Form.PrintXY(5,110,"Password:")
    $Form.PrintXY(5,165,"Select OU Container:")
    $Form.PrintXY(5,380,"Status:")
   
    $Form.FontName = "arial"
    $Form.FontSize = 20
    $Form.FontItalic = True
    $Form.FontBold = True
    $Form.ForeColor = &E3A17A+&151515
    $Form.PrintXY(517,17,"Join AD")
    $Form.ForeColor = &E3A17A-&151515
    $Form.PrintXY(515,15,"Join AD")
   
    $Form.FontSize = 12
    $Form.PrintXY(540,45,$ScriptVersion)
    $Form.ForeColor = Gray
    $Form.FontSize = 10
    $Form.PrintXY(445,70,"Migration Script by NTDOC")
    $Form.ForeColor = BLACK
    $Form.FontSize = 10
    $Form.FontBold = False
    $Form.FontItalic = False
    $Form.PrintXY(445,110,"1: Enter Domain and User ID")
    $Form.PrintXY(445,130,"2: Enter password")
    $Form.PrintXY(445,150,"3: Select OU container")
    $Form.PrintXY(445,170,"4: Click Move Computer")
   
    $txtArea              = $Form.ComboBox
    $txtArea.Bounds      = 3,185,348,150
    $txtArea.Style      = 1
    $txtArea.DropDownWidth   = 348
    $OU1="Computers OU in FINANCE"
    $OU2="Computers OU in GRAPHICS"
    $OU3="Computers OU in ENTERTAINMENT"
    $txtArea.AddItem($OU1)
    $txtArea.AddItem($OU2)
    $txtArea.AddItem($OU3)
   
    $Computer = $Form.TextBox
    $Computer.FontSize = 12
    $Computer.Top = 30
    $Computer.Left = 3
    $Computer.Right = 350
    $Computer.Height = 30
    $Computer.BorderStyle = 4
    $Computer.Text = @WKSTA
    $Computer.FontName = "Courier New"
   
    $Userid = $Form.TextBox
    $Userid.FontSize = 12
    $Userid.Top = 80
    $Userid.Left = 3
    $Userid.Right = 350
    $Userid.Height = 30
    $Userid.BorderStyle = 4
    $Userid.Text = @DOMAIN+'\'+@USERID
    $Userid.FontName = "Courier New"
   
    $UserPass = $Form.TextBox
    $UserPass.FontSize = 12
    $UserPass.Top = 130
    $UserPass.Left = 3
    $UserPass.Right = 350
    $UserPass.Height  = 30
    $UserPass.BorderStyle = 4
    $UserPass.PasswordChar = "*"
    $UserPass.Text = ""
    $UserPass.FontName = "Courier New"
   
    $Move = $Form.ToolButton
    $Move.Alignment = 2
    $Move.FlatStyle = 1
    $Move.left = 455
    $Move.top = 366
    $Move.width = 85
    $Move.height = 85
    $Move.text = "&Move@crlfComputer"
    $Move.Icon = $ImageList.Images(0)
    $Move.border = 3
    $Move.ToolTip = "Moves current computer into the Active Directory"
    $Move.BackColor = 212,208,200
    $Move.OnClick = "Message()"
   
    $Quit = $Form.ToolButton
    $Quit.Alignment = 2
    $Quit.FlatStyle = 1
    $Quit.left = 540
    $Quit.top = 366
    $Quit.width = 85
    $Quit.height = 85
    $Quit.text = "E&xit"
    $Quit.Icon = $ImageList.Images(1)
    $Quit.border = 3
    $Quit.ToolTip = "Exits application without further prompting"
    $Quit.BackColor = 212,208,200
    $Quit.OnClick = "Quit()"

    $Status = $Form.Label
    $Status.Left = 0
    $Status.Top = $Form.ClientHeight-20
    $Status.Height = 20
    $Status.Right = $Form.ClientWidth
    $Status.BackColor = 212,208,200
    $Status.Forecolor = Gray
    $Status.BorderStyle = 5
    $Status.Text = " Powered by Kixtart "+@KIX+" and Kixforms "+$Form.Version
   
    Dim $StringUsername
    Dim $StringPassword
   
    $Form.Center
    $Form.Show
    While $Form.Visible
     $=Execute($Form.DoEvents)
    Loop
   
    Exit 1
    ELSE
     $nul = MESSAGEBOX("You must be logged on with Administrator rights to use this tool. ", "Insufficient Rights", 16)
    EndIF
ELSE
    $nul = MESSAGEBOX("Only Windows 2000/XP supported.   Please use another method to add NT 4.0 systems. ", "Unsupported OS", 16)
    EXIT 199
ENDIF

Function Message()
 DIM $err2
 IF $Computer.Text = ""
   $err2= $Form.MsgBox("You must specify a valid Computer name before clicking Move Computer.", "Invalid Computer name",16)
   $Computer.Text = @WKSTA
   EXIT Sub
 ELSE
   $Computer.Text = $Computer.Text
 ENDIF

 IF $Userid.Text = ""
   $err2= $Form.MsgBox("You must specify a Domain and User ID before clicking Move Computer.", "Invalid Username",16)
   $Userid.Text = $StringUsername
   Exit Sub
 Else
   $StringUsername = $Userid.Text
 EndIf

 If $UserPass.Text = ""
   $err2= $Form.MsgBox("You must specify a password before clicking Move Computer.", "Invalid Password",16)
   $UserPass.Text = $StringPassword
   Exit Sub
 Else
   $StringPassword = $UserPass.Text
 EndIf
SelectOU
EndFunction


Function SelectOU()
DIM $Action, $err
    $Action="MOVE"
Select
  Case $txtArea.text=""
    $err=$Form.MsgBox("Please select a valid OU and try again","Invalid OU Container Selected",16)
  Case $txtArea.text=$OU1
    $MoveComp='@SCRIPTDIR\netdom $Action @wksta /d:businessone.home.company.com /ud:$StringUsername /PD:$StringPassword /ou:ou=computers,ou=businessone,ou=home,dc=company,dc=com /REBOOT'
    SHELL $MoveComp
    ShowResults
  Case $txtArea.text=$OU2
    $MoveComp='@SCRIPTDIR\netdom $Action @wksta /d:businesstwo.home.company.com /ud:$StringUsername /PD:$StringPassword /ou:ou=computers,ou=businesstwo,ou=home,dc=company,dc=com /REBOOT'
    SHELL $MoveComp
    ShowResults
  Case $txtArea.text=$OU3
    $MoveComp='@SCRIPTDIR\netdom $Action @wksta /d:businessthree.home.company.com /ud:$StringUsername /PD:$StringPassword /ou:ou=computers,ou=businessthree,ou=home,dc=company,dc=com /REBOOT'
    SHELL $MoveComp
    ShowResults
  CASE 1
    $err=$Form.MsgBox($txtArea.txt +"There was an unexpected error. Please verify all information and try again","Unexpected Error",16)
EndSelect
EndFunction

Function ShowResults()
  $Message = $Form.TextBox
  $Message.FontSize = 10
  $Message.Top = 400
  $Message.Left = 3
  $Message.Right = 440
  $Message.Height = 50; 200
  $Message.MultiLine = True
  $Message.BorderStyle = 0
  $Message.ScrollBars = 2
  $Message.FontName = "Courier New"
  $Message.Text = "Computer move result: "+@ERROR+'  '+@SERROR
EndFunction

function LocalAdmin()
 $LocalAdmin=ingroup('@wksta\'+sidtoname('S-1-5-32-544'))-1+@inwin
endfunction
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Radimus
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 05 Mar 2003
Posts: 157
Location: Tampa, Florida

PostPosted: Tue Jun 24, 2003 11:13 pm    Post subject: Reply with quote

Would this join to the domain from a workgroup?

I'm looking to modify our disk imaging process, and I was thinking that letting the newly imaged PC come online into a workgroup with it's random name, letting it autoadminlogon once, and start something like this... where it could rename the PC, join the domain, and move to an OU all at once.

What do you think??
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
ntdoc
KiXforms Supporter
KiXforms Supporter


Joined: 05 Mar 2003
Posts: 77
Location: Mouse Country

PostPosted: Tue Jun 24, 2003 11:55 pm    Post subject: Reply with quote

Yes it would, but it MOVES rather then just Joins. We had more issues with Joining then we did with Moves, so I set it to MOVE.

WORKGROUP or DOMAIN are basically the same to the tool, it doesn't care.
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Wed Jun 25, 2003 7:23 am    Post subject: Reply with quote

Ron,

you somehow missed to wrap your code between [code] - tags

_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
Rod
KiXforms Webmaster
KiXforms Webmaster


Joined: 22 Feb 2003
Posts: 202
Location: United Kingdom

PostPosted: Wed Jun 25, 2003 7:51 am    Post subject: Reply with quote

I saved Ron the effort Wink

Rod.

_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Radimus
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 05 Mar 2003
Posts: 157
Location: Tampa, Florida

PostPosted: Mon Jun 30, 2003 2:49 am    Post subject: Reply with quote

here is what I came up with



The disk image it sysprepped to create a random PC name and join to the workgroup. It will autoadmin logon once and start this form from a bat file where it regs and unregs kixforms, and then deletes all the files (except itself)
Code:

regsvr32 /s c:\kixforms.dll
kix32 c:\add.kix
regsvr32 /s /u c:\kixforms.dll


del c:\netdom.exe /q
del c:\add.kix /q
del c:\kix32.exe /q
del c:\kixforms.dll /q


Code:

Break On
$= setconsole("minimize")
$= SetOption( "WrapAtEOL", "ON" )
;********* FORM CREATE BEGIN **********
$Form = CreateObject('Kixtart.Form')
$Form.BackColor = 236,233,216
$Form.ForeColor = 0,0,0
$Form.Left = 99
$Form.Top = 25
$Form.Height = 314
$Form.Width = 240
$Form.FontBold = "False"
$Form.FontItalic = "False"
$Form.FontUnderline = "False"
$Form.FontName = "Microsoft Sans Serif"
$Form.FontSize = 8.25
$Form.Text = "Join PC to mydomain"
$Form.FormBorderStyle = 4
;********* FORM CREATE END **********

;************* LABEL0 **************
$Label0 = $Form.Label
$Label0.BackColor = 236,233,216
$Label0.ForeColor = 255,0,0
$Label0.Left = 15
$Label0.Top = 10
$Label0.Height = 30
$Label0.Width = 250
$Label0.FontBold = "False"
$Label0.FontItalic = "False"
$Label0.FontUnderline = "False"
$Label0.FontName = "Microsoft Sans Serif"
$Label0.FontSize = 14
$Label0.Text = "@wksta"
;*************************************

;************* LABEL1 **************
$Label1 = $Form.Label
$Label1.BackColor = 236,233,216
$Label1.ForeColor = 0,0,0
$Label1.Left = 15
$Label1.Top = 45
$Label1.Height = 23
$Label1.Width = 100
$Label1.FontBold = "False"
$Label1.FontItalic = "False"
$Label1.FontUnderline = "False"
$Label1.FontName = "Microsoft Sans Serif"
$Label1.FontSize = 8.25
$Label1.Text = "New PC Name"
;*************************************

;************* LABEL2 **************
$Label2 = $Form.Label
$Label2.BackColor = 236,233,216
$Label2.ForeColor = 0,0,0
$Label2.Left = 20
$Label2.Top = 105
$Label2.Height = 23
$Label2.Width = 100
$Label2.FontBold = "False"
$Label2.FontItalic = "False"
$Label2.FontUnderline = "False"
$Label2.FontName = "Microsoft Sans Serif"
$Label2.FontSize = 8.25
$Label2.Text = "IT Staff Name"
;*************************************

;************* LABEL3 **************
$Label3 = $Form.Label
$Label3.BackColor = 236,233,216
$Label3.ForeColor = 0,0,0
$Label3.Left = 40
$Label3.Top = 135
$Label3.Height = 23
$Label3.Width = 60
$Label3.FontBold = "False"
$Label3.FontItalic = "False"
$Label3.FontUnderline = "False"
$Label3.FontName = "Microsoft Sans Serif"
$Label3.FontSize = 8.25
$Label3.Text = "Password"
;*************************************

;************* LABEL4 **************
$Label4 = $Form.Label
$Label4.BackColor = 236,233,216
$Label4.ForeColor = 0,0,0
$Label4.Left = 30
$Label4.Top = 75
$Label4.Height = 23
$Label4.Width = 70
$Label4.FontBold = "False"
$Label4.FontItalic = "False"
$Label4.FontUnderline = "False"
$Label4.FontName = "Microsoft Sans Serif"
$Label4.FontSize = 8.25
$Label4.Text = "User to add"
;*************************************

;************* COMPNAME **************
$Compname = $Form.TextBox
$Compname.BackColor = 255,255,255
$Compname.ForeColor = 0,0,0
$Compname.Left = 120
$Compname.Top = 45
$Compname.Height = 20
$Compname.Width = 100
$Compname.FontBold = "False"
$Compname.FontItalic = "False"
$Compname.FontUnderline = "False"
$Compname.FontName = "Microsoft Sans Serif"
$Compname.FontSize = 8.25
$Compname.Multiline = "False"
$Compname.Text = ""
$Compname.PasswordChar = ""
;*************************************

;************* ADDUSER **************
$AddUser = $Form.TextBox
$AddUser.BackColor = 255,255,255
$AddUser.ForeColor = 0,0,0
$AddUser.Left = 120
$AddUser.Top = 75
$AddUser.Height = 20
$AddUser.Width = 100
$AddUser.FontBold = "False"
$AddUser.FontItalic = "False"
$AddUser.FontUnderline = "False"
$AddUser.FontName = "Microsoft Sans Serif"
$AddUser.FontSize = 8.25
$AddUser.Multiline = "False"
$AddUser.Text = "mydomain\"
$AddUser.PasswordChar = ""
;*************************************

;************* DCSA **************
$DCSA = $Form.TextBox
$DCSA.BackColor = 255,255,255
$DCSA.ForeColor = 0,0,0
$DCSA.Left = 120
$DCSA.Top = 105
$DCSA.Height = 20
$DCSA.Width = 100
$DCSA.FontBold = "False"
$DCSA.FontItalic = "False"
$DCSA.FontUnderline = "False"
$DCSA.FontName = "Microsoft Sans Serif"
$DCSA.FontSize = 8.25
$DCSA.Multiline = "False"
$DCSA.Text = "mydomain\"
$DCSA.PasswordChar = ""
;*************************************

;************* DCSAPW **************
$DCSAPW = $Form.TextBox
$DCSAPW.BackColor = 255,255,255
$DCSAPW.ForeColor = 0,0,0
$DCSAPW.Left = 120
$DCSAPW.Top = 135
$DCSAPW.Height = 20
$DCSAPW.Width = 100
$DCSAPW.FontBold = "False"
$DCSAPW.FontItalic = "False"
$DCSAPW.FontUnderline = "False"
$DCSAPW.FontName = "Microsoft Sans Serif"
$DCSAPW.FontSize = 8.25
$DCSAPW.Multiline = "False"
$DCSAPW.Text = ""
$DCSAPW.PasswordChar = "*"
;*************************************

;************* OU **************
$OU = $Form.ComboBox
$OU.Left = 120
$OU.Top = 165
$OU.Height = 21
$OU.Width = 100
;*************************************

;************* LABEL5 **************
$Label5 = $Form.Label
$Label5.BackColor = 236,233,216
$Label5.ForeColor = 0,0,0
$Label5.Left = 15
$Label5.Top = 165
$Label5.Height = 23
$Label5.Width = 100
$Label5.FontBold = "False"
$Label5.FontItalic = "False"
$Label5.FontUnderline = "False"
$Label5.FontName = "Microsoft Sans Serif"
$Label5.FontSize = 8.25
$Label5.Text = "OU to assign to"
;*************************************

;************* EXECUTE **************
$Execute = $Form.Button
$Execute.Text = "Execute"
$Execute.ForeColor = 0,0,0
$Execute.Left = 120
$Execute.Top = 195
$Execute.Height = 23
$Execute.Width = 100
$Execute.FontBold = "False"
$Execute.FontItalic = "False"
$Execute.FontUnderline = "False"
$Execute.FontName = "Microsoft Sans Serif"
$Execute.FontSize = 8.25
$Execute.OnClick = "doit"
;*************************************

;************* STATUS **************
$Status = $Form.ListBox
$Status.BackColor = 255,255,255
$Status.ForeColor = 0,0,0
$Status.Left = 15
$Status.Top = 225
$Status.Height = 45
$Status.Width = 205
$Status.FontBold = "False"
$Status.FontItalic = "False"
$Status.FontUnderline = "False"
$Status.FontName = "Microsoft Sans Serif"
$Status.FontSize = 8.25
$Status.Multiline = "False"
$Status.Text = ""
$Status.PasswordChar = ""
;*************************************

for each $item in split('a01 a02 a03 a04 a05 a06 a07 a08 a09 a10 a11 hq')
   $ou.additem($item)
   next
$ou.text = 'hq'

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

  if  $AddUser.Text     <> 'mydomain\'
  and $DCSA.Text        <> 'mydomain\'
  and len($DCSAPW.Text)  > 6
  and $Compname.Text    <> @wksta
   $Execute.Enabled=1
  else
   $Execute.Enabled=0
   endif
Loop
Exit 1

;***************************************************************************************************************

Function doit()
   if not left($AddUser.Text,5)='mydomain\'   $AddUser.Text='mydomain\'+$AddUser.Text   endif
   if not left($DCSA.Text,5)='mydomain\'   $DCSA.Text='mydomain\'+$DCSA.Text      endif
   if len($DCSA.Text)>6 and len($DCSAPW.Text)>6
      $netdom   ='netdom.exe'
      $oupath ='/OU:OU=Computers,OU='+$ou.text+',DC=mydomain,DC=com'
      $ladmin   ='/userO:adminaccount /passwordO:*******'
      $dadmin   ='/userD:'+$DCSA.Text+' /passwordD:'+$DCSAPW.Text
      $newname='/NewName:'+$Compname.Text
      $domain ='/Domain:mydomain'

      $rename   ='$netdom renamecomputer @wksta $newname $ladmin $dadmin /force /reboot:10'
      $join   ='$netdom join @wksta $domain $oupath $ladmin $dadmin'
      $add   ='net localgroup administrators /add '+$AddUser.Text

      StatusLine('Joining Domain')
      shell 'cmd /c $join'
      $er=@error $ser=@serror
      StatusLine($ser)
      if $er
         $=messagebox("Error Joining Domain","Check IT Account and PW")
         return
         endif
         
      for each $state in split ('stop start')
         StatusLine($state+'ing services')
         for each $service in split('netlogon browser server messenger workstation')
            $=WMIService($service,$state)
            next
         next

      StatusLine('Renaming PC')
      shell 'cmd /c $rename'
      $er=@error $ser=@serror
      StatusLine($ser)
      if $er
         $=messagebox("Error Renaming PC","Ensure New name doesn't exist")
         return
         endif

      StatusLine('Adding User to Local Admin')
      shell 'cmd /c $add'
      StatusLine(@serror)
      if $ou.text<>'hq'
         $svr =$ou.text
         $user=$DCSA.Text
         $pw  =$DCSAPW.Text
         use l: '\\'+$svr+'\logon' /user:$user /password:$pw
         copy l:\LogonNT.lnk '%allusersprofile%\Start Menu\Programs\Startup\'
         endif
      quit
      endif
   EndFunction

FUNCTION StatusLine($text)
   $status.additem($text)
   $status.listindex=$status.listcount-1
   EndFunction

function WMIService($service,optional $action,optional $startmode,optional $computer)
   Dim $wmi,$svc,$services,$sm,$st
   
   if not $computer   $computer=@wksta   endif
   $wmi=getobject("winmgmts:{impersonationlevel=impersonate}!//$computer")
   $services=$wmi.ExecQuery("Select * from Win32_Service where name = '$service'")
   if not @error
      for each $svc in $services
         If instr("AUTOMATIC,MANUAL,DISABLED",$startmode)
            $ = $svc.ChangeStartMode($startmode)
            endif
         if $svc.State <> $action
            select
               case $action = "START"      $ = $svc.StartService()
               case $action = "STOP"      $ = $svc.StopService()
               case $action = "PAUSE"      $ = $svc.PauseService()
               case $action = "RESUME"      $ = $svc.ResumeService()
               endselect
            endif
         next
      $wmi=getobject("winmgmts:{impersonationlevel=impersonate}!//$computer")
      $services=$wmi.ExecQuery("Select * from Win32_Service where name = '$service'")
      for each $svc in $services
         $sm=$svc.StartMode
         $st=$svc.State
         $WMIService = "$st|$sm"
         next
      $wmi=0
   else
      exit 2
      endif
   endfunction
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
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