Jump to content

DriveMapAdd


Recommended Posts

I have a login script i mode over time thats I would like to transfer to Autoit

@echo on
start %logonserver%\netlogon\minwin.exe

set accounts=\\CF-NAS1
set source=\\CF-NAS1
set public=\\public
set chaos=\\CF-NAS1
set music=\\itunes
set itunes=\\itunes
set homebase=\\CF-NAS1 
set printers=%logonserver%
set operation=Normal

call %logonserver%\netlogon\getos ostemp
if "%ostemp%"=="NT40" goto WINNT
if "%ostemp%"=="2000" goto WINNT
if "%ostemp%"=="2002" goto WINNT
if "%ostemp%"=="2003" goto server
if "%ostemp%"=="XP" goto WINNT
if "%ostemp%"=="Ultimate" goto WINNT
if "%ostemp%"=="Business" goto WINNT
if "%ostemp%"=="Enterprize" goto newWINNT
if "%ostemp%"=="Enterprise" goto newWINNT
goto win9x

:newWINNT
rem this is only needed if your accessing external none windows based NAS devices using Vista or Windows 7
rem read this for more help with Vista and windows 7: [url="http://social.technet.microsoft.com/Forums/en-CA/w7itpronetworking/thread/4606ad12-1f23-4231-8597-8e515422d57d"]http://social.technet.microsoft.com/Forums/en-CA/w7itpronetworking/thread/4606ad12-1f23-4231-8597-8e515422d57d[/url]

set operation="Vista and wondows 7"
set accounts=\\10.0.0.3
set source=\\10.0.0.3
set chaos=\\10.0.0.3
set homebase=\\10.0.0.3
goto WINNT

:WINNT
%SystemDrive%

:start
rem (Do not use (abcdefgh) rem (i)(j)(k)(l)(m)(n)o(p)(q)(r)(s)(t)(u)(v)(w)x(y)z

net use * /delete /yes
net time %logonserver% /SET /Y
net use h: %homebase%\user$\%username%

%logonserver%\netlogon\IFMEMBER "%userdomain%\Domain Admins"
IF "%ERRORLEVEL%"=="1" (
net use s: %source%\source
rem net use p:  %public%\public
rem net use i:  %public%\library
goto message
)

:add_printers
if "%ostemp%"=="NT40" goto end_printer_message
if "%ostemp%"=="Ultimate" goto end_printer_message
if "%ostemp%"=="Business" goto end_printer_message
if "%ostemp%"=="Enterprize" goto end_printer_message
rundll32 printui.dll,PrintUIEntry /in /n"%printers%\hp4250n" /q
rundll32 printui.dll,PrintUIEntry /in /n"%printers%\HP4700n" /q
goto end_printer_run
:end_printer_message
start %logonserver%\netlogon\WINMSG.exe -t "OS Network Printer Message" -m "Hello %username%\n\nIt is advised that you install the printer drivers for your OS manually.\nDrivers for this os is not suppored in automatic install mode, and could course issues with your system.\n\nPlease call Peter on 0772-700781 for advice\n\nEnjoy :-)" -w 25
:end_printer_run

%logonserver%\netlogon\IFMEMBER "%userdomain%\core"
IF "%ERRORLEVEL%"=="1" (
net use x: %accounts%\core$
net use q: %accounts%\quickbooks$
net use t: %accounts%\clients$
net use u: %accounts%\suppliers$
rem net use i: %itunes%\itunes
)

%logonserver%\netlogon\IFMEMBER "%userdomain%\quoteworks"
IF "%ERRORLEVEL%"=="1" (
net use w: %source%\quotewerks
)


%logonserver%\netlogon\IFMEMBER "%userdomain%\engineers"
IF "%ERRORLEVEL%"=="1" (
net use s: %source%\source
net use v: %source%\recovery
)

%logonserver%\netlogon\IFMEMBER "%userdomain%\domain users"
IF "%ERRORLEVEL%"=="1" (
net use n: %chaos%\localcoms$
rem net use p: %public%\public
rem net use m: %music%\music
)

:message
start %logonserver%\netlogon\WINMSG.exe -t "Welcome to %userdomain% network" -m "Welcome %username% to the %userdomain% Network\n\nIf you have any problems or questions with your account please contact your support.\nCall Support on xxxxx-xxxxxx\n\nEnjoy :-)\n\n Logon script in %operation% mode login via %computername% on Server %longonserver%" -w 4
goto end

:win9x
echo this domain fully supports Windows NT/XP/2000, 2003, 2008, Vista and Windows 7 workstations, with partial support for Windows 64bit OS and none for the rest sorry!
echo os version %ostemp%
pause

:end
:server

The problem I am having that that I wish to change the URL (//server/share_name) to and IP based (//10.0.0.3/share_name) to get round the issues that Windows 7 & and Vista have when accessing none windows storage devices.

In order for me to do that I need to be able to done something like

$accounts=""10.0.0.3""
mapdrive("x:",$accounts & "\core$")

I know the double quotes for the $accounts string are present and incorrect but it was the only way I could stop this board changing the text within, sorry.

Any helpful advise will be more than welcome.

[topic='115020'] AD Domain Logon Script[/topic]

Link to comment
Share on other sites

In order for me to do that I need to be able to done something like

$accounts=""10.0.0.3""
mapdrive("x:",$accounts & "\core$")

I know the double quotes for the $accounts string are present and incorrect but it was the only way I could stop this board changing the text within, sorry.

I don't understand what the issue with the IP is. This looks correct (and the doubled quotes are not required, single quotes will do):
$accounts = "10.0.0.3"
DriveMapAdd("x:", "\\" & $accounts & "\core$")

This maps X: to the \\10.0.0.3\core$ share. If credentials are required, the user will be prompted. See DriveMapAdd() in the help file.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

its sorted

mapdrive("x:",$accounts & "core$")
I add this so others may benefit if useful.
Where is mapdrive()?

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Where is mapdrive()?

Posted Image

Func mapdrive($DriveLtr, $DrivePath)
DriveMapAdd($DriveLtr, $DrivePath, 1)
if @error = "1" Then
MsgBox (16, "Error", "An unknown error occured on "& $DrivePath & " trying to be mapped as local drive " & $DriveLtr)
ElseIf @error = "2" Then
MsgBox (16, "Error", "Access to the remote share "& $DrivePath & " was denied")
ElseIf @error = "3" Then
MsgBox (16, "Error", "The device/drive "& $DriveLtr &" is already assigned")
ElseIf @error = "4" Then
MsgBox (16, "Error", "Invalid device "& $DriveLtr &" name")
ElseIf @error = "5" Then
MsgBox (16, "Error", "Invalid remote share :" & $DrivePath)
ElseIf @error = "6" Then
MsgBox (16, "Error", "Invalid password")
Else
MsgBox (64, "Completed!", "Mapped " & $DriveLtr & " to share " & $DrivePath)
EndIf
EndFunc

DriveMapAdd is a function built into Autoit, along with others that can be found usinf the Autoit help file, just search for MapDriveAdd and it will lead you to the rest..

Edited by PeterAtkin

[topic='115020'] AD Domain Logon Script[/topic]

Link to comment
Share on other sites

DriveMapAdd is a function built into Autoit, along with others that can be found usinf the Autoit help file, just search for MapDriveAdd and it will lead you to the rest..

:D

I think it might have been safe to assume I knew that!

:huggles:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Posted Image

I think it might have been safe to assume I knew that!

Posted Image

Opss sorry seems the reply came in out of order.. just as an update the script is now fully functional so thanks for the positive responce.

#include <Constants.au3>
#include <Array.au3>
#include <NetShare.au3>

Global $Paused
;Function keys to pause or terminate the script
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{END}", "Terminate")
Global $ostemp

Global $network_printers[2]
;last printer becomes the default
$network_printers[0] = "[url="file://\dc-2008hp4700n"]\\dc-2008\hp4700n[/url]"
$network_printers[1] = "[url="file://\dc-2008hp4250n"]\\dc-2008\hp4250n[/url]"

Global $var_printer = UBound($network_printers) - 1
Global $cmd = UBound($CmdLine) - 1

Switch OSGet()
 Case 'vista_win'
  ;this is only needed if your accessing external none windows based NAS devices using Vista or Windows 7
  ;read this for more help with Vista and windows 7: [url="http://social.technet.microsoft.com/Forums/en-CA/w7itpronetworking/thread/4606ad12-1f23-4231-8597-8e515422d57d"]http://social.technet.microsoft.com/Forums/en-CA/w7itpronetworking/thread/4606ad12-1f23-4231-8597-8e515422d57d[/url] $operation="Vista and Windows 7"
  $accounts = "[url="file://\10.0.0.3"]\\10.0.0.3[/url]"
  $source = "[url="file://\10.0.0.3"]\\10.0.0.3[/url]"
  $chaos = "[url="file://\10.0.0.3"]\\10.0.0.3[/url]"
  $homebase = "[url="file://\10.0.0.3"]\\10.0.0.3[/url]"
  $operation = "Vista or Windows 7 Mode"
 Case 'winnt'
  $accounts = "[url="file://\CF-NAS1"]\\CF-NAS1[/url]"
  $source = "[url="file://\CF-NAS1"]\\CF-NAS1[/url]"
  $chaos = "[url="file://\CF-NAS1"]\\CF-NAS1[/url]"
  $homebase = "[url="file://\CF-NAS1"]\\CF-NAS1[/url]"
  $operation = "XP Mode"
 Case 'server'
  mapdrive("s:", $source & "\source")
  Exit
 Case Else
  MsgBox(16, "OS Incompatability", "this domain fully supports Windows NT/XP/2000, 2003, 2008, Vista and Windows 7 workstations, with partial support for Windows 64bit OS and none for the rest sorry!" & @CRLF & @CRLF & "OS version " & @OSVersion)
EndSwitch

If $CmdLine[0] = 0 Then
Else
 ReadCmdLineParams()
EndIf

Func ReadCmdLineParams()
 For $i = 1 To $cmd
  Select
   Case $CmdLine[$i] = "-update"
    ; put code here
   Case $CmdLine[$i] = "-newcomputer"
    ; put code here
   Case Else
    ; put code here
  EndSelect
 Next
EndFunc   ;==>ReadCmdLineParams

If _CMD(@LogonServer & '\netlogon\ifmember Domain Users') Then
 RunAs("Administrator", "cfu", "password", 4, "net time " & @LogonServer & " /SET /Y", @SW_HIDE)
 ShellExecuteWait("net", "use * /delete /yes", "", "", @SW_HIDE)
 mapdrive("h:", $homebase & "\user$\" & @UserName)
 mapdrive("n:", $chaos & "\localcoms$")
 add_network_printers()
EndIf

If _CMD(@LogonServer & '\netlogon\ifmember Domain Admins') Then
 mapdrive("s:", $source & "\source")
EndIf

If _CMD(@LogonServer & '\netlogon\ifmember quoteworks') Then
 mapdrive("w:", $accounts & "\quotewerks")
EndIf

If _CMD(@LogonServer & '\netlogon\ifmember core') Then
 mapdrive("x:", $accounts & "\core$")
 mapdrive("q:", $accounts & "\quickbooks$")
 mapdrive("t:", $accounts & "\clients$")
 mapdrive("u:", $accounts & "\suppliers$")
EndIf

If _CMD(@LogonServer & '\netlogon\ifmember Engineers') Then
 mapdrive("s:", $source & "\source")
EndIf
_users()
_welcome()

Func _users()
 Switch @UserName
  Case 'Peter'
   ;MsgBox(16, "Hello", "peter")
  Case 'Tasha'
   ;MsgBox(16, "Hello", "Tasha")
  Case 'Administrator'
   MsgBox(32, "OS Version Machine Diags", "User " & @UserName & " on computer " & @ComputerName & " running OS " & @OSVersion & " " & @OSArch & " Architecture", 10)
 EndSwitch
EndFunc   ;==>_users

Func _welcome()
 $local_domain = EnvGet("userdomain")
 $domain_server = EnvGet("logonserver")
 MsgBox(64, "Welcome to the " & $local_domain & " network", "Welcome " & @UserName & " to the " & $local_domain & " Network" & @CRLF & @CRLF & "If you have any problems or questions with your account please contact support. Peter on xxxxx-xxxxxx" & @CRLF & @CRLF & "Enjoy" & @CRLF & @CRLF & "Logon script in " & $operation & " login on " & @ComputerName & " via Server " & $domain_server)
EndFunc   ;==>_welcome


Func add_network_printers()
 For $x = 0 To $var_printer Step 1
  _PrinterAdd($network_printers[$x], 1)
 Next
EndFunc   ;==>add_network_printers

Func mapdrive($DriveLtr, $DrivePath)
 DriveMapAdd($DriveLtr, $DrivePath, 1)
 Switch @error
  Case '1'
   MsgBox(16, "Error", "An unknown error occured on " & $DrivePath & " trying to be mapped as local drive " & $DriveLtr)
  Case '2'
   MsgBox(16, "Error", "Access to the remote share " & $DrivePath & " was denied")
  Case '3'
   MsgBox(16, "Error", "The device/drive " & $DriveLtr & " is already assigned")
  Case '4'
   MsgBox(16, "Error", "Invalid device " & $DriveLtr & " name")
  Case '5'
   MsgBox(16, "Error", "Invalid remote share :" & $DrivePath)
  Case '6'
   MsgBox(16, "Error", "Invalid password")
  Case Else
   ;MsgBox(64, "Completed!", "Mapped " & $DriveLtr & " to share " & $DrivePath)
 EndSwitch
EndFunc   ;==>mapdrive

Func _CMD($command, $workingdir = '')
 Return RunWait('"' & @ComSpec & '" /c ' & $command, $workingdir, @SW_HIDE)
EndFunc   ;==>_CMD

Func OSGet()
 Switch @OSVersion
  Case "WIN_7"
   $ostemp = "vista_win7"
  Case "WIN_XP"
   $ostemp = "winnt"
  Case "Win_2000"
   $ostemp = "winnt"
  Case "WIN_VISTA"
   $ostemp = "vista_win7"
  Case "WIN_2008"
   $ostemp = "server"
  Case "WIN_2008R2"
   $ostemp = "server"
  Case "WIN_2003"
   $ostemp = "server"
  Case Else
   MsgBox(32, "OS Version Machine Diags", "User " & @UserName & " on computer " & @ComputerName & " running OS " & @OSVersion & " " & @OSArch & " Architecture", 10)
   Exit
 EndSwitch
 ArchGet()
EndFunc   ;==>OSGet

Func ArchGet()
 Switch @OSArch
  Case "X86"
  Case Else
   MsgBox(32, "32/64bit Architecture", "User " & @UserName & " on computer " & @ComputerName & " running OS " & @OSVersion & " " & @OSArch & " Architecture", 10)
   Exit
 EndSwitch
EndFunc   ;==>ArchGet


;===============================================================================
;
; Function Name:    _PrinterAdd()
; Description:      Connects to a Network Printer.
; Parameter(s):     $sPrinterName - Computer Network name and printer share name ([url="file://\ComputerSharedPrinter"]\\Computer\SharedPrinter[/url]).
;                   $fDefault - Set to 1 if Printer should be set to default (optional).
; Requirement(s):
; Return Value(s):  1 - Success, 0 - Failure, If Printer already exist @error = 1.
; Author(s):        Sven Ullstad - Wooltown
; Note(s):          None.
;
;===============================================================================
Func _PrinterAdd($sPrinterName, $fDefault = 0)
 If _PrinterExist($sPrinterName) Then
  SetError(1)
  Return 0
 Else
  RunWait("rundll32 printui.dll,PrintUIEntry /in /n" & $sPrinterName & " /q")
  If _PrinterExist($sPrinterName) = 0 Then
   Return 0
  EndIf
  If $fDefault = 1 Then
   _PrinterDefault($sPrinterName)
  EndIf
  Return 1
 EndIf
EndFunc   ;==>_PrinterAdd

;===============================================================================
;
; Function Name:    _PrinterDefault()
; Description:      Set a printer to default.
; Parameter(s):     $sPrinterName - The name of the printer.
; Requirement(s):
; Return Value(s):  1 - Success, 0 - Failure.
; Author(s):        Sven Ullstad - Wooltown
; Note(s):          None.
;
;===============================================================================
Func _PrinterDefault($sPrinterName)
 If _PrinterExist($sPrinterName) Then
  RunWait("rundll32 printui.dll,PrintUIEntry /y /n" & $sPrinterName)
  Return 1
 Else
  Return 0
 EndIf
EndFunc   ;==>_PrinterDefault

;===============================================================================
;
; Function Name:    _PrinterDelete()
; Description:      Delete a connection to a network printer.
; Parameter(s):     $sPrinterName - Computer Network name and printer share name.
; Requirement(s):
; Return Value(s):  1 - Success, 0 - Failure.
; Author(s):        Sven Ullstad - Wooltown
; Note(s):          None.
;
;===============================================================================
Func _PrinterDelete($sPrinterName)
 If _PrinterExist($sPrinterName) Then
  RunWait("rundll32 printui.dll,PrintUIEntry /dn /n" & $sPrinterName)
  If _PrinterExist($sPrinterName) Then
   Return 0
  Else
   Return 1
  EndIf
 Else
  Return 0
 EndIf
EndFunc   ;==>_PrinterDelete

;===============================================================================
;
; Function Name:    _PrinterExist()
; Description:      Check if a Printer Exist.
; Parameter(s):     $sPrinterName - The name of the printer.
; Requirement(s):
; Return Value(s):  1 - Success, 0 - Failure.
; Author(s):        Sven Ullstad - Wooltown
; Note(s):          None.
;
;===============================================================================
Func _PrinterExist($sPrinterName)
 Local $hService, $sPrinter, $sPrinterList
 $hService = ObjGet("winmgmts:{impersonationLevel=impersonate}!" & "\\" & @ComputerName & "\root\cimv2")
 If Not @error = 0 Then
  Return 0
 EndIf
 $sPrinterList = $hService.ExecQuery("Select * From Win32_Printer")
 For $sPrinter In $sPrinterList
  If StringUpper($sPrinterName) = StringUpper($sPrinter.name) Then
   Return 1
  EndIf
 Next
EndFunc   ;==>_PrinterExist

Func TogglePause()
 $Paused = Not $Paused
 While $Paused
  Sleep(100)
  ToolTip('Script is "Paused"', (1), (8), (1), (8))
 WEnd
 ToolTip("")
EndFunc   ;==>TogglePause

Func Terminate()
 Exit
EndFunc   ;==>Terminate

Please find complete solution within, it still relies on an external function ifmember.exe but I am trying to work out a solution for that if possible.

Edited by PeterAtkin

[topic='115020'] AD Domain Logon Script[/topic]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...