• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 370
  • Last Modified:

Sharing a CD drive in vb.net

I am trying to write a server application that will run on a PC and when requested from a client will share the CDROM drive to a client for a short period of time.  My server program will listens on a port using winsock and then when I get a request I want to programatially create a share and send the share name back to the Client to use.  Then when the client is done, I want to delete it.  I am stuck on programatically creating the share on the server and then on the client creatinng a mapped drive to it.  Anyone have any samples in VB.NEt on how do this?  I have everything working but Creating the share on the server.  and then just mapping it in the client.  the client program does have the ip address of the server for mapping.
0
edfrazier
Asked:
edfrazier
  • 2
  • 2
1 Solution
 
therock_Commented:
1) programatially create a share and send the share name back to the Client to use.
well you can use shell commands like net share to create and delete share drive like ....
To create share =>   Shell("net share MyDvdDrive=L:\", AppWinStyle.Hide, True, 50)
To delete share =>   Shell("net share L:\  /delete", AppWinStyle.Hide, True, 50)
here you can create random share name or use any fixed one instead MyDvdDrive.
or just try => net share /? in dos
or you can write function like
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=4035&lngWId=10
or
http://www.codeproject.com/dotnet/pinvokeaddshare.asp

2)Mapping Drive
 Same for here also. you can use shell commands then open mapped drive programmatically.
To map drive => Shell("net use Z \\**.**.**.**\sharename /user:username pass",AppWinStyle.Hide, True, 50)
To delete mapped drive => Shell("net use Z: /delete",AppWinStyle.Hide, True, 50)

here z is the drive letter to connect. you can use whatever you want(except used once).
help =>  net use /?
http://www.mredkj.com/vbnet/vbnetmapdrive.html
or
http://www.dotnet4all.com/dotnet-code/2004/10/how-to-map-network-drive-in-code.html
or
http://www.dotnet247.com/247reference/msgs/4/22781.aspx

Try it out. may be this can help
0
 
edfrazierAuthor Commented:
Thanks, This seems simple.  I will give it a try and let you know
0
 
edfrazierAuthor Commented:
It seems easy but it does not seem to work with Vista.  i guess this is becuase of the tight security Vista uses?
0
 
therock_Commented:
i guess so...
1) try to execute program(your_program.exe) with administrator rights
2) Or you can try this way. but it will show command prompt while executing the command
Dim theSecureString As New Security.SecureString()
        theSecureString.AppendChar("p")
        theSecureString.AppendChar("a")
        theSecureString.AppendChar("s")
        theSecureString.AppendChar("s")
        theSecureString.AppendChar("w")
        theSecureString.AppendChar("o")
        theSecureString.AppendChar("r")
        theSecureString.AppendChar("d")

        Process.Start("net", " share MyDvdDrive=L:\", "Administrator", theSecureString, "")
About SecureString =>
Represents text that should be kept confidential. The text is encrypted for privacy when being used, and deleted from computer memory when no longer needed.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=661112&SiteID=1

0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now