Willmaykett
(Fresh Scripter)
2007-01-07 01:52 PM
Identifying a drive mapping, writing to then readfing from file

Hi all,

Absolute newbie to Kixtart, with no previous scripting experience, so please be kind to me

I want to use Kix to perform the following functions:

1. Find out the server and full share name of a mapped drive letter, eg P:. This share can include spaces, & etc.

2. If the drive is not mapped, write out to an appended error file. If the drive exists, write out the unc path to a file. Should only need to be a single line.

3. I then need to be able to read the line of the file, so that I can use it to map a new drive letter against the share.

Not sure about how to attack part 1, for part 2 and 3 I think I need a combination of writeline, readline and obviously use commands. I am looking for assistance for a nice easy way of doing it, so I can start to understand and modify as I go.

Thanks for the anticipated help.
Willy


LonkeroAdministrator
(KiX Master Guru)
2007-01-07 03:09 PM
Re: Identifying a drive mapping, writing to then readfing from file

hmm...
why you want to write to file?


LonkeroAdministrator
(KiX Master Guru)
2007-01-07 04:12 PM
Re: Identifying a drive mapping, writing to then readfing from file

please provide some info about the actual write process and why you need it.
simply writing a textfile might not be the best way if you wanna use the info with some other script or program.
if you want the file for logging purposes only, then it's another deal.


Les
(KiX Master)
2007-01-07 04:27 PM
Re: Identifying a drive mapping, writing to then readfing from file

I'm confused why KiX would have to pull the info back from the text file. I mean, if KiX wrote it in the first place it should already know the value unless the script that wrote it is different from the one reading it.

In that case a serial text file is probably not the way to go. Use an INI file instead.


Sealeopard
(KiX Master)
2007-01-07 09:56 PM
Re: Identifying a drive mapping, writing to then readfing from file

Drive mappings are stord in the registry under HKCU\Network. You can then use ArrayEnumKey UDF to enumerate the mapped drive letters.

LonkeroAdministrator
(KiX Master Guru)
2007-01-07 10:36 PM
Re: Identifying a drive mapping, writing to then readfing from file

hmm...
there is udf's for enuming the mapped drives too.
don't think that's the issue now.
at least I wanna hear back from this guy before offering anything deeper...


Willmaykett
(Fresh Scripter)
2007-01-08 12:39 AM
Re: Identifying a drive mapping, writing to then readfing from file

Thanks for all the responses!

These are the requirements behind the intial request.

Currently, each user ( about 400 ) use a multitude of dos batch files when logging in. There exists a batch file which maps a P: drive to their own unique location, so the current batch file has 400 or If %username% = user , then map p: to \\server\share\xxxxx. Same goes for the group mappings, Really cool.... not. As you can imaging, there are people who do not have a P: drive, then stuff breaks and call the HelpDesk cause someone goofed in the batch file.

I have started implementing kix to replace the horrendous group drives, and that works well. But the P: drive is a bit more interesting, especially as a migration is underway at the moment.

1. I need to determine their existing P: drive when they login in, rather than try and find what they currently map too in the batch file.
2. I am required to write this file into their home directory.
3. Whenever they log back in, this file is then parsed to determine the share folder and directory.
4. The drive is then mapped accordingly.
5. Whenever the user logs off a script will be used to check and rewrite the contents of the file if they have changed the P: drive mapping.

The reason for this method is that the local IT department has determined that this is the way they want to control the users P: drive and can then update for the user as needed.

Willy

I hope this make more sense.


AllenAdministrator
(KiX Supporter)
2007-01-08 02:18 AM
Re: Identifying a drive mapping, writing to then readfing from file

If all of your workstations are Windows 2000 or higher you could make your life a whole lot easier. Just rename the users folders to match their user names. Then share the Users folder. IE...
Root
  Users <--shared
    User1
    User2
    User3

Finally in your kixscript...

use p: "\\Server\Share\" + @userid


Willmaykett
(Fresh Scripter)
2007-01-08 02:59 AM
Re: Identifying a drive mapping, writing to then readfing from file

The P: drive mapping is used by the users to map to different folder structures within a common share, often referred to as the "personal preference drive". This is in addition to their normal home drive, so unfortunately, I can't use your suggestion.

I need the following:

Stage 1:

1. Read the users current P: drive.
2. Write the results to a text file. Should only be a single line with \\server\share\folder

stage 2:
1. Read the contents of the text file from step 2 above
2. Then do a use command to map a drive.

There must be a file created that is stored in the users home directory.

Thanks


Sealeopard
(KiX Master)
2007-01-08 03:51 AM
Re: Identifying a drive mapping, writing to then readfing from file

Set a default personla preference file if one doesn't exist yet.

Les
(KiX Master)
2007-01-08 04:05 AM
Re: Identifying a drive mapping, writing to then readfing from file

Having different drive mappings in a common share area is just a bad idea. When users create links within shared documents, their link would be to their *preference* and be broken for others.

I do not use any sort of *preference* mappings in my logon script but some of my users map personal drives and are forever causing problems with invalid links. They also make verbal reference to them causing support calls.


Willmaykett
(Fresh Scripter)
2007-01-08 04:05 AM
Re: Identifying a drive mapping, writing to then readfing from file

Thats exactly what I want to do, is to generate the file.

Started exploring the HCU option, and then writing that to the file.

Any code ideas?


AllenAdministrator
(KiX Supporter)
2007-01-08 04:33 AM
Re: Identifying a drive mapping, writing to then readfing from file

I'm glad to help you with this... but I got to tell you, fixing this problem rather than putting a bandaid on it is your best bet... What if they delete this file after you create it? Anyway... not trying to preach ;\)

Using EnumNetworkDrives()
Code:
For each $Drive in EnumNetworkDrives()  
  $letter=Split($Drive,",")[0]
  $path= Split($Drive,",")[1]
  if $letter="p:"
    ? $letter + " " + $path
    ;Write this info to a text file or ini file
  endif
Next 
 


Willmaykett
(Fresh Scripter)
2007-01-08 05:12 AM
Re: Identifying a drive mapping, writing to then readfing from file

Hi Allen,

I can certainly understand your point, but they have been used to it for a number of years, and let's say... " We had it for a number of years, we like it, why should we change it....." and believe me, it ain't worth the frustration. As they say, you want a mini minor, I will give you a mini minor, but not without trying to upsell first. Response...Pass on that thanks....

BTW - The files live in a configuration folder, and users know if they delete any files in there, they cop the wrath of the IT support lady...

That looks nice and easy, I will incorporate that in the script.

thanks!


Willmaykett
(Fresh Scripter)
2007-01-08 06:37 AM
Re: Identifying a drive mapping, writing to then readfing from file

Hi Allen,

Incorporated the EnumNetworkDrives() UDF and you code snippet, I have now successfully been able to write out the text file. I have incorporated the kix script into the users normal login scripts and I have been able to extract everyones P: drive !!

Thanks heaps for your help!! Onya

Willy