cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Nejchy
Level 4

Share INSTALLDIR folder

Is it posible to share a INSTALLDIR folder prior or after the installation?

Thank you for your help.
Labels (1)
0 Kudos
(9) Replies
Nejchy
Level 4

Nejchy wrote:
Is it posible to share a INSTALLDIR folder prior or after the installation?

Thank you for your help.


Maybe i wasn't clear enough.
I want to create a Windows folder share, so that it will be visible to other computer across the network.
0 Kudos
cbragg
Level 7

You can't do it through the tables but you can do it via a custom action.

You can run this vbscript as a deferred custom action:

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, "My shared folder description"


You then create an immediate execute custom action to set a property. You can call it anything you like but the property you are setting needs to be the name of the custom action you created with the script. The value needs to be the folder you are sharing. E.g. [INSTALLDIR]

Hope this helps
0 Kudos
Nejchy
Level 4

Thank for the answer. I'm sure the script works, but i have problems setting it.

Could you confirm that what i'm doing is right?

I created a new vbscript custom action stored in custom action.
It's name is NewCustomAction. I also set in-script execution to deferred.

Then i created new custom action set property. It's name is NewProperty.
Property name:shareProperty
Property value:[INSTALLDIR]

Then i changed Session.Property("CustomActionData") to Session.Property("shareProperty") and also added parenthesis to the
objNewShare.Create(strFilePath, "'MyShare'", _
FILE_SHARE, MAXIMUM_CONNECTIONS, "My shared folder description")

But as i'm a complete beginner i don't know when or in which order to call these two custom actions.
Now i'm first calling NewProperty in Install Exec Sequence after ScheduleReboot and NewCustomAction after NewProperty.

When i run this i get: Error 1720.

What did i do wrong?

Thanks for your help.
0 Kudos
Nejchy
Level 4

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("shareProperty")
strFilePath = Left(strFilePath, Len(strFilePath) - 1)
objNewShare.Create strFilePath, "'MyShare'", _
FILE_SHARE, MAXIMUM_CONNECTIONS, "My shared folder description"


I just found that there is a problem with the Left method.

The error is invalid procedure call or argument:'Left'
0 Kudos
cbragg
Level 7

Ok I can see what went wrong. The problem with deferred custom actions is that you don't get access to properties using the Session.Property method easily. So the solution i gave you is a well known tip on getting properties into deferred custom actions. So where you went wrong is this:

The property name you are changing should not be shareProperty it should be the name of the script custom action so you are setting the property name NewCustomAction instead (matches the name of your customaction called NewCustomAction). When you set a property with the same name as the custom action you can refer to it in the scripts as Session.Property("CustomActionData") so you will need to put the script back to using this.
The reason the Left didn't work is because it was trying to work out the left on a null value because it can't access your property shareProperty directly in deferred mode.

As for sequencing I tend to put the set property action just before costfinalize and then you can set the script custom action anywhere you like between installinitialize and installfinalize.

Hope this helps 🙂
0 Kudos
Nejchy
Level 4

It works.

Thank you.
0 Kudos
SteveLovell
Level 5

Thank you so much for this thread, I have just got this working (InstallShield 2011).
0 Kudos
ChristianS
Level 4

Is there a way to do this in an InstallScript project as well?
The documentation suggests that this solution only works with Basic MSI or InstallScript MSI.
0 Kudos
reihane
Level 2

hi
i have problem and i need to help you
i do this action but no folder become share!!!! i do not have error
please help me. i need it
😞
0 Kudos