Sharing INSTALLDIR windows folder in InstallShield - cmd

I want to share my setup directory in installshield. I did some search and found a VB Script and a CMD Command:
Option Explicit
Const FILE_SHARE = 0
Const MAXIMUM_CONNECTIONS = 25
Dim objShare
'Connect to WMI
Dim objWMIService: Set objWMIService = _
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
'Query share names for existing share
Dim colShares: Set colShares = objWMIService.ExecQuery _
("Select * from Win32_Share Where Name = 'MyShare'")
'Delete share if one exists with the same name already
For Each objShare in colShares
objShare.Delete
Next
'Create new share
Dim objNewShare: Set objNewShare = objWMIService.Get("Win32_Share")
Dim strFilePath: strFilePath = Session.Property("CustomActionData")
strFilePath = Left(strFilePath, Len(strFilePath) - 1)
objNewShare.Create strFilePath, "MyShare", _
FILE_SHARE, MAXIMUM_CONNECTIONS, "MyShare"
cmd command:
net share sharename=[INSTALLDIR]
When i run VBScript i don't see any error but I can't share my folder.
When i run cmd command, command can't share because it requires admin privilege; but I am not sure, how i can provide admin privilege to it;
can i share folder? how?

Try. You need to have access rights on location that you are trying to share.
net share Share=E:\Shared /Grant:Everyone,full
Note: You can change the share rights based on your need. This is strictly an example.

i found a very simple solution. i went in file and folders tab and right clicked on installdir an then in sharing tab i checked Share Folder check box and Finish! Very Simple Without code and Command!

Related

How to run WMI commands on non-domain-joined server from script running using domain admin credentials

I have a windows script running from a scheduled task, set to run with domain credentials.
It checks the disk space on all of my domain joined servers using WMI.
Set wmi = GetObject("winmgmts:\\" & hostname & "\root\cimv2")
...
Set wmiresults = wmi.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE Name = '" & _
UCase(diskletter) & ":'")
For Each wmiresult In wmiresults
ptotalspace = Round(CDbl(wmiresult.Size) / 1073741824, 2)
pfreespace = Round(CDbl(wmiresult.Freespace) / 1073741824, 2)
Next
This script works fine for all domain joined servers. But I need to include a non-domain-joined server into this checking, and it fails as the script lacks the necessary permissions on the target server.
I have tried the hacky method of creating a local user account with the same name and password as the domain admin acct, and adding it to local admins, but this didn't work.
Is there a way to allow the script permission to check the server's disks without joining it to the domain, and without having to create a duplicate or version of this script that runs using a local account with permission to perform this check?
The solution is here: Connecting to WMI Remotely with VBScript
Look at option 2 under the heading "To connect to a remote system using VBScript". You can use the SWbemLocator.ConnectServer method to pass different credentials to the connection. It looks like this:
strComputer = "Computer_B"
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, _
"Root\CIMv2", _
"fabrikam\administrator", _
"password")
Just replace "fabrikam\administrator" and "password" with a username and password that has permission on that machine. Then you can use that objSWbemServices object the same way you were using your wmi object.
That should work if you run it from a machine inside the domain too... I think. Give it a try.

VBScript (HTA) MapNetworkDrive - Logon Failure

I am trying to create a HTA file that, among other things, connects to a remote network drive on a Windows 7 PC. In order to do this I need a username / password. I have the following code:
Sub ConnectDrive
Set objNetwork = CreateObject("WScript.Network")
Set oShell = CreateObject("Shell.Application")
objNetwork.MapNetworkDrive "x:", "\\testsystem3\temp", False, User, Pass
If Err.Number = 0 Then
oShell.NameSpace("x:").Self.Name = "Temp on TS3"
End If
Set oShell = Nothing
Set objNetwork = Nothing
End Sub
User and Pass are the actual username and password used in order to connect.
The problem is that I get a Logon failure error message: "Logon failure: unknown user name or bad password".
I am sure that the username and password are ok since using the net use x: \\testsystem3\temp /user:User pass command connects the drive successfully.
Any suggestions how to get this to work? I could turn off password protected sharing on the Windows 7 machine but I wouldn't like that...
Thank you!

How to get clientsitename and object status in windows 2000

As we know it's easy to get client site name in windows 2003 via WMI_NTdomain.clientsitename, object status by WMI_NTdomain.status , but that class doesn't exist in Windows 2000. So can you show me how to get those value by script or command line?
My old system is still running well on windows 2000, i don't want to change it at now.
Grab HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Netlogon\Parameters\DynamicSiteName with reg.exe, vbscript, or your favorite scripting/programing language.
Edit:
I admit that I haven't seen W2k for some time now. Does this VB Script output usefull information:
option explicit
dim adSys
Set adSys = CreateObject("ADSystemInfo")
WScript.Echo "SiteName=" & adSys.SiteName
'WScript.Echo "Computername DN=" & adSys.ComputerName
'WScript.Echo "Username DN=" & adSys.UserName
'WScript.Echo "DomainDNSName (Comp)=" & adSys.DomainDNSName
'WScript.Echo "DomainShortName (Comp)=" & adSys.DomainShortName
'WScript.Echo "ForestDNSName (Comp)=" & adSys.ForestDNSName
You could also use the WMI ScriptOMatic to search for the relevent class.

Reset password for renamed Administrator account

I need to create a .VBS script to reset the Windows local administrator password on a large group of computers. My problem is that some of our sites have renamed the administrator account for security reasons. Does anyone have a script which changes the password of the administrator account based on the SID of the original Administrator account?
Using the fact that local admin's SID always ends with -500:
strComputer="." ' local computer by default
Set objUser=GetObject("WinNT://" & strComputer & "/" & GetAdminName & ",user")
objUser.SetPassword "New local admin password"
objUser.SetInfo
Function GetAdminName
'This function was written using information from Table J.1 from the Windows XP resource Kit
'http://www.microsoft.com/resources/documentation/Windows/XP/all/reskit/en-us/Default.asp?url=/resources/documentation/Windows/XP/all/reskit/en-us/prnc_sid_cids.asp
Set objNetwork = CreateObject("Wscript.Network") 'get the current computer name
objComputerName = objNetwork.ComputerName
Set objwmi = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & objComputerName)
qry = "SELECT * FROM Win32_Account where Domain = '" & cstr(objComputerName) & "'"
'set query, making sure to only look at local computer
For Each Admin in objwmi.ExecQuery(qry)
if (left(admin.sid, 6) = "S-1-5-" and right(admin.sid,4) = "-500") then 'look for admin sid
GetAdminName = admin.name
end if
next
end Function
There's a tool floating around somewhere called LookupAccountName (with source!) that given the SID of the builtin adminitrator will give you its name.
You're probably going to end up writing C++ code to pull this one off reasonably well.
Like Joshua says, I don't think you can do this with windows scripting host only, you could use it download something and execute it:
A custom app that calls LookupAccountSid(S-1-5-domain-500 SID or enum admin group)+NetUserSetInfo to reset the password (Needs to run this as admin)
http://home.eunet.no/pnordahl/ntpasswd/ (Reset at boot)
Dump the SAM hashes and crack the password (Cain,John the Ripper,L0phtCrack etc)
#DmitryK's answer is good, and I didn't know any of that stuff. But I do know that this sort of thing is usually cleaner in PowerShell, so I ported it.
For example, the whole GetAdminName function can be written:
$adminName = (gwmi win32_account | ? { $.SID.StartsWith( 'S-1-5-' ) -and $.SID.EndsWith( '-500' ) }).Name
(Add the -ComputerName option to the gwmi call to do this on a server.)
The rest becomes:
$user = ([ADSI]"WinNT://$($env:COMPUTERNAME)/$adminName,User")
$user.SetPassword( 'xxx' )
$user.SetInfo()
(applying the appropriate computer name as needed, of course.)

Retrieve all users from Active Directory (LDAP) using VBScript

How can I retrieve all users from Active Directory using VBScript?
Dim oDomain = GetObject("LDAP://OU=YourOU,DC=YourDomain,DC=com")
For Each oUser in oDomain
WScript.echo oUser.Get("distinguishedName")
Maybe this will get you running?

Resources