Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Script - Install File and Printer sharing

64 views
Skip to first unread message

Bill

unread,
Oct 7, 2003, 8:29:07 AM10/7/03
to
Is there a way using script to install File and Printer
Sharing?

I am new to script, and have looked at the sample code on
installing a service.

http://www.microsoft.com/technet/scriptcenter/services/scr
svc12.asp

Torgeir Bakken (MVP)

unread,
Oct 7, 2003, 9:54:36 AM10/7/03
to
Bill wrote:

> Is there a way using script to install File and Printer
> Sharing?
>
> I am new to script, and have looked at the sample code on
> installing a service.

Hi

I only know how to install it by using snetcfg.exe, like this:

snetcfg.exe -v -l %windir%\Inf\NETSERV.INF -c s -i MS_Server

If you want to use Snetcfg.exe to _enable_ File & Print Sharing (F&PS already
installed, but the checkbox is not checked), you will have to uninstall F&PS
first, and then install again. This will make the checkbox checked.

snetcfg.exe -v -u MS_Server
snetcfg.exe -v -l %windir%\Inf\NETSERV.INF -c s -i MS_Server


Snetcfg is a sample tool in the MS Driver Development Kit
(...\src\network\config\netcfg) that must be compiled into an exe from the
source (C/C++?) before it can be used. It can list, install and uninstall most
network components (note: Win2k and WinXP only).

More about MS Driver Development Kit here:
http://www.microsoft.com/whdc/ddk/winddk.mspx

Fortunately, you can download a compiled version of Snetcfg.exe (note
different version depending on OS) at
http://www.jsiinc.com/reghack.htm, tip 4705

Here is a script that should do the job by first uninstalling (just in case)
and then installing F&Ps (you will need to update the content of the
sSnetcfgPath variable):

SetLocale "en-us" ' do not remove

If GetOsVersionNumber = 5.0 Then
sSnetcfgPath = "some path to snetcfg.exe for WinXP"
Elseif GetOsVersionNumber = 5.1 Then
sSnetcfgPath = "some path to snetcfg.exe for WinXP"
Else
' unsupported OS
WScript.Quit
End If

Set oShell = CreateObject("WScript.Shell")

sUninstCmd = Chr(34) & sSnetcfgPath & Chr(34) & " -u MS_Server"
oShell.Run sUninstCmd, 0, True

sInstCmd = Chr(34) & sSnetcfgPath & Chr(34) & " -l " _
& "%windir%\Inf\NETSERV.INF -c s -i MS_Server"
oShell.Run sInstCmd, 0, True


Function GetOsVersionNumber()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Determines OS by reading reg val & comparing to known values
' OS version number returned as number of type double:
' Windows 2k: 5
' Windows XP: 5.1
' Windows Server 2003: 5.2
' Windows x: >5.2

' Note: Decimal point returned is based on the Locale setting
' of the computer, so it might be returned as 5,1 as well.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim oShell, sOStype, sOSversion
Set oShell = CreateObject("Wscript.Shell")

On Error Resume Next
sOStype = oShell.RegRead(_
"HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions\ProductType")
If Err.Number<>0 Then
' Hex(Err.Number)="80070002"
' - Could not find this key, OS must be Win9x
Err.Clear

sOStype = oShell.RegRead(_
"HKLM\SOFTWARE\Microsoft\Windows" & _
"\CurrentVersion\VersionNumber")

Select Case sOStype
Case "4.00.950"
sOSversion = 1 ' Windows 95A
Case "4.00.1111"
Dim sSubVersion
sSubVersion = oShell.RegRead(_
"HKLM\SOFTWARE\Microsoft\Windows" & _
"\CurrentVersion\SubVersionNumber")
Select Case sSubVersion
Case " B"
sOSversion = 1 ' Windows 95B
Case " C"
sOSversion = 1 ' Windows 95C
Case Else
sOSversion = 1 ' Unknown Windows 95
End Select
Case "4.03.1214"
sOSversion = 1 ' Windows 95B
Case "4.10.1998"
sOSversion = 2 ' Windows 98
Case "4.10.2222"
sOSversion = 2 ' Windows 98SE
Case "4.90.3000"
sOSversion = 3 ' Windows Me
Case Else
sOSversion = 1 ' Unknown W9x/Me
End Select
Else ' OS is NT based
sOSversion = oShell.RegRead(_
"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")
If Err.Number<>0 Then
GetOsVersion = "Unknown NTx"
' Could not determine NT version
Exit Function ' >>>
End If
End If

' Setting Locale to "en-us" to be indifferent to country settings.
' CDbl might err else
SetLocale "en-us"
GetOsVersionNumber = CDbl(sOSversion)
End Function

--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter


bf792

unread,
Oct 8, 2003, 1:47:12 PM10/8/03
to
Thanks for the info, I'll give it a try.

Bill

"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
news:3F82C59C...@hydro.com...

0 new messages