Page 1 of 2 12>
Topic Options
#33641 - 2002-11-29 12:06 AM Check if a share is mapped to
Julian Offline
Starting to like KiXtart

Registered: 2000-04-20
Posts: 112
Loc: Newcastle, Staffs, UK
Hi,

I was wondering if anybody could help me. I have written a script to move the user directories from one server to another. First of all in unshares the directory then copies it to the new location and then reshares it. I was wondering if there is a way i can check if that users directory is been mapped to before i unshare it so there is no chance of data loss. here is the code below:

code:
;Start Move
$UserDirList="G:\MoveDirs\Dirs.txt"
Open(1,$UserDirList,2)
$Dir=Readline(1)
While $Dir<>""
$SourceShare=$SourceServer + $Dir ; Share on source server to be removed
$DestShare=$DestServer + $Dir ; Share on destination server to be created
$SourceUserDir=$SourceDir + $Dir ; Path of the user dir on source server
$DestUserDir=$DestSharePath + $Dir ; Path of the user dir on destination server
$RmtUserDir=$MappedDrive + $Dir ; Location on the source server of the destination path
Shell "RmtShare $SourceShare /DELETE"
Shell "Robocopy $SourceUserDir $RmtUserDir /E /SEC /MOVE /XF paradox.cfg /+LOG:MoveUserDir.txt"
Shell "RmtShare $DestShare=$DestUserDir"
Shell "NTUser -s $PDC change $Dir -home_dir $DestServer$Dir -home_dir_drive $HomeDirDrive"
$Dir=Readline(1)
Loop
Close(1)
Return

I basically like something in the code that checks if the share is in use, if it is then it skips the whole lot.

any ideas?

thanks

Top
#33642 - 2002-11-28 02:25 PM Re: Check if a share is mapped to
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
Have a look at the USE LIST command...
quote:
Use

Action: Enables you to list the current connections. Also enables you to connect a device, such as a drive or a printer, to a network resource; or to disconnect a device from a network resource.

Syntax: USE LIST


_________________________
We all live in a Yellow Subroutine...

Top
#33643 - 2002-11-28 03:03 PM Re: Check if a share is mapped to
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
The only thing I can think of is an old trick to limit concurrent connections. Sounds kludgy but hey... it's early in the morning and I'm still on my first cup of coffee.

It is done by limiting the number of users to the share to 1. If you then try to map to the share and it fails then there must be 1 already mapped.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#33644 - 2002-11-28 03:26 PM Re: Check if a share is mapped to
Julian Offline
Starting to like KiXtart

Registered: 2000-04-20
Posts: 112
Loc: Newcastle, Staffs, UK
Thanks for your input but I think we may be on cross purposes here. I want to be able to check whether or not somebody, the user, is mapped to the share on the server. The USE LIST command just tells which drives are mapped on the server [Frown] .

The scernario goes. The script fisrt checks if any user is mapped to the share, if not its unshared, moved, then reshared. If a user is mapped to it, it is just ignored.

Sorry if I didnt explain my self to well. [Razz]

Ju

Top
#33645 - 2002-11-28 03:38 PM Re: Check if a share is mapped to
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
You want to check the server share for active connections, right?

This can be done. If I can not find a way to get this info via COM I will add the functionality to my Win32Admin.DLL.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#33646 - 2002-11-28 03:39 PM Re: Check if a share is mapped to
Julian Offline
Starting to like KiXtart

Registered: 2000-04-20
Posts: 112
Loc: Newcastle, Staffs, UK
thats right yes. thankyou.
Top
#33647 - 2002-11-28 03:45 PM Re: Check if a share is mapped to
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
What about -

IF EXIST("E:\")
..

or

IF GETFILEATTR("E:\") & 16
..

HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#33648 - 2002-11-28 03:56 PM Re: Check if a share is mapped to
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Today is a U.S. holiday. I will not be able to get to this until after dinner. It may be easier for me to provide you an EXE that does the whole thing since I already have most of this coded in Perl for something I have already done. Would that be acceptable?

[ 28. November 2002, 15:57: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#33649 - 2002-11-28 03:58 PM Re: Check if a share is mapped to
Julian Offline
Starting to like KiXtart

Registered: 2000-04-20
Posts: 112
Loc: Newcastle, Staffs, UK
That would be fantastic. Will it be fairly straigtforward to incorporate it into my script?
Top
#33650 - 2002-11-28 03:59 PM Re: Check if a share is mapped to
Julian Offline
Starting to like KiXtart

Registered: 2000-04-20
Posts: 112
Loc: Newcastle, Staffs, UK
kdyer - Im sorry im not quite with you on that, how would those commands help? [Roll Eyes]
Top
#33651 - 2002-11-28 04:00 PM Re: Check if a share is mapped to
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
OK, I think Howard and I are on the right track. This is an admin script that is moving shares and you want to make sure the share is not in use when you move it.

This would be the same as from 'Server Manager' 'Shares' show connected users. Don't know if an RK util exists or a CL command.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#33652 - 2002-11-28 04:12 PM Re: Check if a share is mapped to
Julian Offline
Starting to like KiXtart

Registered: 2000-04-20
Posts: 112
Loc: Newcastle, Staffs, UK
Thats exactly it. Ive had a good look the the resource kits but cant seem to find a tool that would fit my needs. [Frown]
Top
#33653 - 2002-11-28 04:18 PM Re: Check if a share is mapped to
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
My two thoughts are that: 1) I would add a method to the Win32Admin.DLL that would query the sever for the number of connections or list of accounts connected to the share. Or 2) I would replace your entire script with an executable that would accept command line parms and do your task end to end.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#33654 - 2002-11-28 04:21 PM Re: Check if a share is mapped to
Julian Offline
Starting to like KiXtart

Registered: 2000-04-20
Posts: 112
Loc: Newcastle, Staffs, UK
I think your going past the realsm of my understanding there Howard. [Eek!]

I havnt got a clue how to turn my entire scrip into an .exe.

maybe one day.

Top
#33655 - 2002-11-28 04:27 PM Re: Check if a share is mapped to
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
My second option is to write what you want in Perl, compile it for you, and provide a complete solution that you could use.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#33656 - 2002-11-28 04:31 PM Re: Check if a share is mapped to
Julian Offline
Starting to like KiXtart

Registered: 2000-04-20
Posts: 112
Loc: Newcastle, Staffs, UK
Well. Ofcourse that would be fantastic but I really would'nt want to put you out. Its quite cheeky. [Razz]

How do you run a Perl script anyway? Ive heard so much about them recently but have never looked into them.

Top
#33657 - 2002-11-28 04:36 PM Re: Check if a share is mapped to
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
FWIW...
Here's more on the kludge approach mentioned by Les...
Pause a busy share
_________________________
We all live in a Yellow Subroutine...

Top
#33658 - 2002-11-28 04:46 PM Re: Check if a share is mapped to
Julian Offline
Starting to like KiXtart

Registered: 2000-04-20
Posts: 112
Loc: Newcastle, Staffs, UK
One command I have come across is the NET SHARE 'ShareName' which displays all users currently connected to that particular share amongst other information. However I wouldnt know how to use the output in my script. [Confused]
Top
#33659 - 2002-11-29 05:32 AM Re: Check if a share is mapped to
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Julian, you can now use Win32Admin.DLL to check the number of active connections to a remote share. You can create a share, delete a share, get/set share properties on a remote server.

You can also use the DLL to get/set user account properties such as home directory and home drive.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#33660 - 2002-12-02 11:32 AM Re: Check if a share is mapped to
Julian Offline
Starting to like KiXtart

Registered: 2000-04-20
Posts: 112
Loc: Newcastle, Staffs, UK
Thanks very much for your help with this. I am going to give it a go tonight.

Thanks

Ju

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.076 seconds in which 0.028 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org