Sign in to follow this  
Followers 0
Tietcth

Enable Print and File Sharing

14 posts in this topic

#1 ·  Posted (edited)

I need to enable the file and print sharing in the connection properties. I have the script developed to do what I want mostly except I need to have a if exist in the script to check if the box is already checked. Any help would be appreciated. (Oh yeah by the way this is for windows xp)

MsgBox(0,"System Changes","System changes in progress by your IT department........",10)

;Lock mouse and keyboard

BlockInput(1)

; Open Network Connections Control Panel applet

Run("control ncpa.cpl")

WinWaitActive("Network Connections")

; Selects Local Area Connection properties

Send("l")

Send("!F")

Send("r")

WinWaitActive("Local Area Connection")

; Select File And Printer Sharing for Microsoft Networks

send("File")

Send("{TAB 5}")

Send("{ENTER}")

; Close Local Area Connection properties screen and Network Connections window

WinClose("Network Connections")

;Unlock mouse and keyboard

Blockinput(0)

test.au3

Edited by Tietcth

Share this post


Link to post
Share on other sites



search for _Net_Share_ShareAdd

It can help you! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

search for _Net_Share_ShareAdd

It can help you! Posted Image

Im trying to just enable file and printer sharing so I can install the symantec Endpoint protection client remotely. File and printer sharing has to be turned on unfortunately to do the install remotely.

Share this post


Link to post
Share on other sites

Im trying to just enable file and printer sharing so I can install the symantec Endpoint protection client remotely. File and printer sharing has to be turned on unfortunately to do the install remotely.

Basically, I need help with writing the part of the script that varifies whether the box for file and printer sharing is checked or not and if it is checked then end script. If it isnt checked then continue on with the script. I guess you would call it get check box value?

Share this post


Link to post
Share on other sites

Basically, I need help with writing the part of the script that varifies whether the box for file and printer sharing is checked or not and if it is checked then end script. If it isnt checked then continue on with the script. I guess you would call it get check box value?

I found this If GuiCTRLRead ($Checkbox1) = $GUI_CHECKED Then but cant seem to manipulate it to work for me.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

i use contrlcommand and there is a "IsChecked" that returns a 1 if checked and a 0 if not and you can use the same command to check or uncheck the box. I have also found it better to use that send because you can tie it to button instances.

damon

oh, and to answer your question,

$var = guictrlread($checkbox1)

msgbox (0,"",$var)

1 = checked

4 = unchecked

so you could do

$var = guictrlread($checkbox1)

if $var = 1 then

msgbox(0,"","Checked")

else

msgbox(0,"","Unchecked")

endif

Edited by damon

It always amazes me how one little thing can cause so much havoc

Share this post


Link to post
Share on other sites

i use contrlcommand and there is a "IsChecked" that returns a 1 if checked and a 0 if not and you can use the same command to check or uncheck the box. I have also found it better to use that send because you can tie it to button instances.

damon

oh, and to answer your question,

$var = guictrlread($checkbox1)

msgbox (0,"",$var)

1 = checked

4 = unchecked

so you could do

$var = guictrlread($checkbox1)

if $var = 1 then

msgbox(0,"","Checked")

else

msgbox(0,"","Unchecked")

endif

Im getting an error: Variable used without being declared when I run the script.

Share this post


Link to post
Share on other sites

Im getting an error: Variable used without being declared when I run the script.

This is what I have so far

Global $CHECKBOX1 = "file and printer sharing for microsoft networks"

MsgBox(0,"Please wait","System changes in progress by your IT department........",10)

;Lock mouse and keyboard

BlockInput(1)

; Open Network Connections Control Panel applet

Run("control ncpa.cpl")

WinWaitActive("Network Connections")

; Selects Local Area Connection properties

Send("l")

Send("!F")

Send("r")

WinWaitActive("Local Area Connection")

;Checkbox state

$var = GUICtrlRead($CHECKBOX1)

if $var = 4 Then

else

if $var = 1 then

EndIf

;Enable file and printer sharing

send("File ")

Send("{TAB 5}")

Send("{ENTER}")

; Close Local Area Connection properties screen and Network Connections window

WinClose("Network Connections")

;Unlock mouse and keyboard

BlockInput(0)

Share this post


Link to post
Share on other sites

anyone have any more ideas or comments?

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Why not just use

RunWait(@Comspec & ' /c netsh firewall set service type = fileandprint mode = enable')
RegWrite('HKLM\SYSTEM\CurrentControlSet\Control\Lsa', 'forceguest', 'REG_DWORD', '0')
I know it is depreciated in Windows 7, but it still works and saves you from messing with the listview

Edited by Varian

Share this post


Link to post
Share on other sites

Why not just use

RunWait(@Comspec & ' /c netsh firewall set service type = fileandprint mode = enable')
RegWrite('HKLM\SYSTEM\CurrentControlSet\Control\Lsa', 'forceguest', 'REG_DWORD', '0')
I know it is depreciated in Windows 7, but it still works and saves you from messing with the listview

I modified that registry entry and it doesnt seem to enable file and print sharing. I can do the firewall with policy but the actual file and print sharing in the network connections I cant via policy. Any other ideas?

Share this post


Link to post
Share on other sites

I modified that registry entry and it doesnt seem to enable file and print sharing. I can do the firewall with policy but the actual file and print sharing in the network connections I cant via policy. Any other ideas?

forceguest is to enable or disable simple file sharing.

Share this post


Link to post
Share on other sites

You are right..my solution doesn't help. I modified your script that should work on x86 windows 7 but I am not sure on x64...I know it does not work on my 2008R2 which is x64. Let me know if it works on a 64-bit Windows 7 box (if you have one)

#include <GuiListView.au3>
#include <Misc.au3>
_Singleton(@ScriptName, 0)

Global $hListView, $hItemFound
Global $sTitle = '[REGEXPTITLE:(?i)Network Connections; CLASS:CabinetWClass]'
Global $wTitle = '[REGEXPTITLE:(?i)Local Area Connection]'

Global $CHECKBOX1 = 'File And Printer Sharing For Microsoft Networks'
MsgBox(0,'Please wait','System changes in progress by your IT department........',10)
;Lock mouse and keyboard
BlockInput(1)
;Open Network Connections Control Panel applet
Run('control ncpa.cpl')
WinWait($sTitle, '')
Do
    WinActivate($sTitle, '')
Until WinActive($sTitle, '')
; Selects Local Area Connection properties
ControlSend($sTitle, '', '', 'l')
ControlSend($sTitle, '', '', '!F')
ControlSend($sTitle, '', '', 'r')
WinWaitActive($wTitle, '')

$hListView = ControlGetHandle($wTitle, '', 'SysListView321')
$ItemCount = _GUICtrlListView_GetItemCount($hListView)

For $i = 0 To $ItemCount - 1
    Do
        WinActivate($wTitle, '')
    Until WinActive($wTitle, '')
    _GUICtrlListView_SetItemSelected($hListView, $i)
    $Text = _GUICtrlListView_GetItemText($hListView, $i)
    ;Sleep(50)
    If StringInStr($Text, 'Sharing') Then
        $State = _GUICtrlListView_GetItemState($hListView, $i, $LVIS_STATEIMAGEMASK)
        Switch $State
            Case 8192 ;Item is Checked
                ControlClick($wTitle, '', 'Button7')
                WinWaitClose($wTitle, '')
                WinClose($sTitle, '')
                ExitLoop    ;Do nothing Here Since Already Checked
            Case 12288 ;Item is unchecked
                ControlSend($wTitle, '', $hListView, '{SPACE}')
                ControlClick($wTitle, '', 'Button6')
                WinWaitClose($wTitle, '')
                WinClose($sTitle, '')
            EndSwitch
        ExitLoop
    EndIf
    ControlSend($wTitle, '', $hListView, '{DOWN}')
Next
BlockInput(0)

Share this post


Link to post
Share on other sites

Thanks so much for your help! I really appreciate it.

You are right..my solution doesn't help. I modified your script that should work on x86 windows 7 but I am not sure on x64...I know it does not work on my 2008R2 which is x64. Let me know if it works on a 64-bit Windows 7 box (if you have one)

#include <GuiListView.au3>
#include <Misc.au3>
_Singleton(@ScriptName, 0)

Global $hListView, $hItemFound
Global $sTitle = '[REGEXPTITLE:(?i)Network Connections; CLASS:CabinetWClass]'
Global $wTitle = '[REGEXPTITLE:(?i)Local Area Connection]'

Global $CHECKBOX1 = 'File And Printer Sharing For Microsoft Networks'
MsgBox(0,'Please wait','System changes in progress by your IT department........',10)
;Lock mouse and keyboard
BlockInput(1)
;Open Network Connections Control Panel applet
Run('control ncpa.cpl')
WinWait($sTitle, '')
Do
    WinActivate($sTitle, '')
Until WinActive($sTitle, '')
; Selects Local Area Connection properties
ControlSend($sTitle, '', '', 'l')
ControlSend($sTitle, '', '', '!F')
ControlSend($sTitle, '', '', 'r')
WinWaitActive($wTitle, '')

$hListView = ControlGetHandle($wTitle, '', 'SysListView321')
$ItemCount = _GUICtrlListView_GetItemCount($hListView)

For $i = 0 To $ItemCount - 1
    Do
        WinActivate($wTitle, '')
    Until WinActive($wTitle, '')
    _GUICtrlListView_SetItemSelected($hListView, $i)
    $Text = _GUICtrlListView_GetItemText($hListView, $i)
    ;Sleep(50)
    If StringInStr($Text, 'Sharing') Then
        $State = _GUICtrlListView_GetItemState($hListView, $i, $LVIS_STATEIMAGEMASK)
        Switch $State
            Case 8192 ;Item is Checked
                ControlClick($wTitle, '', 'Button7')
                WinWaitClose($wTitle, '')
                WinClose($sTitle, '')
                ExitLoop    ;Do nothing Here Since Already Checked
            Case 12288 ;Item is unchecked
                ControlSend($wTitle, '', $hListView, '{SPACE}')
                ControlClick($wTitle, '', 'Button6')
                WinWaitClose($wTitle, '')
                WinClose($sTitle, '')
            EndSwitch
        ExitLoop
    EndIf
    ControlSend($wTitle, '', $hListView, '{DOWN}')
Next
BlockInput(0)

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