Jump to content

Create SMB Share on Workstation


tazdev
 Share

Recommended Posts

Recently I have had to deal with a lot of customers who want to send documents to a share on their own PC. Keep in mind I always recommend using a server for SMB shares however, some people don't have a server or enough people to warrant having a server. I made the following so that my technician can have this on a flash drive and it will create a share exactly the same way each time so I know what was done in case there is an issue. 

It will create the share (If it exists then it does not change the share called scan)

It will create the user (if the user exists it will not modify that user)

It will create a password for that user (If the user exists it will not change anything)

It will create a shortcut to the share on the desktop

It will grant the user full rights to the share both in permissions and security

I hope you find it useful. It can probably be made cleaner but it does work for me so I don't mess with it too much. It will also create a TXT doc on the screen for the tech to use and a TXT file on the flash drive as a backup so they will know what was done.

BTW, I just realized that I have a myshortcut.vbs file that gets installed. The VBS is noted in the notes in the script so you can make it if you want or incorporate it.

#cs
 
Creates a folder on the root of C: called scans
Creates a local user scan on the PC
Attempts to create a share called scans based on the folder above, if it already exists then it does nothing
Adds full control to everyone
adds scan user full permissions to the share
Pops up a notepad with the information for the customer to save and the tech to read off or print out
Since I do not know what the actual folder name is of the share I cannot create a shortcut
Created on a workstations create a shortcut using the unc \\@computername\scans
VBS Stuff in case I am on a PC that does not have the script:
---------------------------------
set WshShell = WScript.CreateObject("WScript.Shell" )
set oShellLink = WshShell.CreateShortcut(Wscript.Arguments.Named("shortcut") & ".lnk")
oShellLink.TargetPath = Wscript.Arguments.Named("target")
oShellLink.WindowStyle = 1
oShellLink.Save
---------------------------------
#ce
 
#include <array.au3>
#include <string.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
 
; Declare vars -----------------------------------------
#Region Declare Variables
Global $ver = "1.051"
Global $uName = "scan"
Global $hName = @ComputerName
Global $lPath = "C:\scans"
Global $tFname = "deleteme.txt"
Global $sName = "scans"
Global $uPassword = "Scanningpass"
Local $cntr = 1
Global $shareCmdE = "net share scans=" & $lPath & " /grant:everyone,FULL"
Global $shareCmdS = "cacls " & $lPath & " /T /E /G " & $uName & ":f"
Global $userCmds = "net user " & $uName & " " & $uPassword & " /ADD /FULLNAME:Scan_Acct"
Local $iFileExists = FileExists ($lPath&"\"&$tFname)
; Get the customer name
Global $cName = InputBox(" Customer Name", "Please enter the Customer Name:","","")
Global $subject = """Scan setup for " & $cName & " <- Company"""
Global $cFile = @ScriptDir & "\" & $cname & "\" & $cName & "_scans.txt"
Global $txt = "Share name: \\" & @ComputerName & "\" & $sName & @CR & "User: " & $uName & @CR & "Password: " & $uPassword & @CRLF & "Please save for future reference" & @CR & "Version: " & $ver
Global $txtEmail = """Share name: \\" & @ComputerName & "\" & $sName & " ""& vbCRLF & """ & "User: " & $uName & " ""& vbCRLF & """ & "Password: " & $uPassword & """ & vbCRLF & """ & "OS: " & @OSARCH & " - " & @UserName & " - " & @OSVersion & """ & vbCRLF & """ & "Version: " & $ver & " """
 
#EndRegion
 
#Region Start_of_Program
FileInstall( "C:\mkshortcut.vbs", @ScriptDir&"\mkshortcut.vbs", 1)
NameofCompany()
If $iFileExists Then
makeshare()
Else
FileOpen($lPath&"\"&$tFname,9)
makeshare()
EndIf
FileClose( $cFile )
FileClose($lPath&"\"&$tFname)
FileDelete($lPath&"\"&$tFname)
 
#EndRegion
 
Func NameofCompany()
;$nowild = 1
$nowildq = StringInStr( $cName, "?")
$nowildstar = StringInStr( $cName, "*")
$nowildbk = StringInStr( $cName, "\")
$nowildfwd = StringInStr( $cName, "/")
$nowild = $nowildbk + $nowildfwd + $nowildq + $nowildstar
;MsgBox (0,"Nowild", $nowild & @CRLF & "$nowildstar: " & $nowildstar)
While $nowild <> 0
$nowildq = StringInStr( $cName, "?")
$nowildstar = StringInStr( $cName, "*")
$nowildbk = StringInStr( $cName, "\")
$nowildfwd = StringInStr( $cName, "/")
$nowild = $nowildbk + $nowildfwd + $nowildq + $nowildstar
;MsgBox (0,"Nowild", $nowild & @CRLF & "$nowildstar: " & $nowildstar)
Global $cName = InputBox(" Customer Name", "Name cannot contain * ? / or \" & @CRLF & "Please enter the Customer Name:","","")
$nowildq = StringInStr( $cName, "?")
$nowildstar = StringInStr( $cName, "*")
$nowildbk = StringInStr( $cName, "\")
$nowildfwd = StringInStr( $cName, "/")
$nowild = $nowildbk + $nowildfwd + $nowildq + $nowildstar
;MsgBox (0,"Nowild", $nowild & @CRLF & "$nowildstar: " & $nowildstar)
WEnd
;MsgBox(0,"test", $nowild & @CRLF & $cname)
EndFunc
 
Func makeshare()
RunWait( @ComSpec & " /c" & $usercmds, @ScriptDir, @SW_HIDE)
RunWait( @ComSpec & " /c" & $sharecmde, @ScriptDir, @SW_HIDE)
RunWait( @ComSpec & " /c" & $sharecmds, @ScriptDir, @SW_HIDE)
RunWait( @ComSpec & " /c" & "mkshortcut /target:""\\" & $hName & "\" & $sName & """ /shortcut:""ScannedDocs""", @ScriptDir, @SW_HIDE)
FileCopy( @ScriptDir & "\ScannedDocs.lnk",@DesktopCommonDir & "\ScannedDocs.lnk")
FileOpen ( $cFile, 9)
FileWriteLine ($cFile, $txt)
FileClose ($cfile)
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send ( $txt )
FileDelete(@ScriptDir&"\ScannedDocs.lnk")
FileDelete(@ScriptDir&"\mkshortcut.vbs")
EndFunc
Edited by tazdev
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

×
×
  • Create New...