Page 1 of 1 1
Topic Options
#210479 - 2015-08-04 10:54 PM If exist file then delete with Wildcards
hroberts89436 Offline
Fresh Scripter

Registered: 2015-08-04
Posts: 11
Loc: Reno, NV
We are moving from drive mappings batch file in startup to a Kix script. I would like to be able to verify it the drive mapping file exists and if so then delete it. The issue is each person who build these PC's used different names, but all should have the name drive somewhere in the file. What I would like to do is something like this. Please let me know if this would work, or if you have a better suggestion:

If Exist ("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\*drive*.bat")
Del ("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\*drive*.bat")
ENDIF

Thank you for any help you can provide me on this. I really don't want to have to go around and touch over 700 PC's

Top
#210480 - 2015-08-04 11:29 PM Re: If exist file then delete with Wildcards [Re: hroberts89436]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
I have had mixed results over the years using the asterisk in kixtart, and just learned to work around it. Here is how I would do it (untested)

 Code:
for each $file in dirplus("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup","/f bat")
  if instr($file,"Drive")
    ? $file 
    ;del $file
  endif
next


You will need to unrem the del line once you have tested it, and you will need to copy the dirplus UDF linked below into your script.


Dirplus -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=82153

How to use UDFs -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=81943#Post81943

The rest of the UDFs are here -
http://www.kixtart.org/forums/ubbthreads.php?ubb=postlist&Board=7&page=1


Top
#210481 - 2015-08-04 11:31 PM Re: If exist file then delete with Wildcards [Re: Allen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
I can't remember, but this location may require admin privs to delete the bat file, so keep that in mind.
Top
#210483 - 2015-08-05 01:42 AM Re: If exist file then delete with Wildcards [Re: Allen]
hroberts89436 Offline
Fresh Scripter

Registered: 2015-08-04
Posts: 11
Loc: Reno, NV
Thank you for the Info. If Admin rights are needed, any way around that?
Top
#210484 - 2015-08-05 02:14 AM Re: If exist file then delete with Wildcards [Re: hroberts89436]
hroberts89436 Offline
Fresh Scripter

Registered: 2015-08-04
Posts: 11
Loc: Reno, NV
How can I use the above, calling the function from another file dirplus.kxf instead of making my kix file even larger?
Top
#210485 - 2015-08-05 02:22 AM Re: If exist file then delete with Wildcards [Re: hroberts89436]
hroberts89436 Offline
Fresh Scripter

Registered: 2015-08-04
Posts: 11
Loc: Reno, NV
Nevermind the last question I figured it out. I need to place the include "dirplus.kxf" at the top of the script
Top
#210489 - 2015-08-06 12:01 AM Re: If exist file then delete with Wildcards [Re: hroberts89436]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Whether you call the external function file or include it directly in your code, the end result is essentially the same - the entire script and function files will be loaded in memory.

One concern I've always had was that as the external UDFs are updated, you never know when your apps will break - you need to test everything. I wrote a KGen utility that identifies which UDFs are in my library, what UDFs are referenced in my script, and then it automatically creates a .KIX file with all the required functions in it. That script will always work, even (especially) when I send it to a client who may not have the UDF library available (in the same paths, etc). Thus, I always use KGen and always include all the UDFs in my scripts as a single package.

When I update a UDF, I can re-run the KGen tool against my script and test - if it works, I can update the package. If it doesn't, I start with checking the most recently modified UDFs for compatibility issues, fix them, and re-gen.

I use Kix and a library of over 260 UDFs in commercial applications every day. The scripts need to work everywhere, every time. Packaging all of the UDFs into the script and Tokenizing insures this.

Glenn

PS - you can download the KGEN utility, User Guide, and our entire production UDF library from the web site in my sig if you want to give it a try.
_________________________
Actually I am a Rocket Scientist! \:D

Top
#210494 - 2015-08-07 01:56 AM Re: If exist file then delete with Wildcards [Re: Glenn Barnas]
hroberts89436 Offline
Fresh Scripter

Registered: 2015-08-04
Posts: 11
Loc: Reno, NV
OK going back to the needing admin rights. I have come across during testing that the dirplus udf above identifies the files, but does not delete the file unless the script is ran as an admin. So here is what I would like to do. I would like to create a folder on a share accessable by all. in that folder I would like to create a txt file with the PC name if it error'd while deleting that file. Is that possible? What would be the best way to add that section to my script
Top
#210495 - 2015-08-07 02:25 AM Re: If exist file then delete with Wildcards [Re: hroberts89436]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Something simple like this might be enough to give you the computer you need to check with a admin script...

 Code:
$log="\\server\share\log.ini"
for each $file in dirplus("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup","/f bat")
  if instr($file,"Drive")
    ? $file 
    ;del $file
    if exist($file)
      $RC=writeprofilestring($log,"PCs",@wksta,$file)
    endif
  endif
next


Top
#210496 - 2015-08-07 02:32 AM Re: If exist file then delete with Wildcards [Re: hroberts89436]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
What you need is the "Secure Admin Install Suite". This handy-dandy script "cures what ails ya"! (and no Snake Oil!)

Here's the general idea:
Your (non admin) user needs to do something that requires admin rights.. install an app, delete a file, whatever.. but you ain't granting no admin rights to them - no-siree-sir!

You use the SAIS (noted above) - you write a small script that is invoked during logon to DETECT if the admin task is needed. That script uses the SAIS API to drop a request on one of your servers - no admin rights needed. (that share can be WRITABLE by all users, but not readable!)

The SAIS service, running on the server, gets the request, verifies it, then looks up the task that was requested. Lickety-split - it sends a script back to the requesting computer and, using the Task Scheduler, defines a Task and immediately executes it with the appropriate admin rights.

So - where can you get this magical application, you ask??? Well, right here on KORG! Just mosey on over to the Script Vault (Click the Forums link, then scroll to the bottom of the forum list).

Now - this does require some coding on your part. The monitor service is fully coded, and the API provides a couple of functions and example code to communicate to the SAIS server. YOU have to write the part of the code that determines if something has to be done, and use the API to submit the request. YOU also need to define the config file on the server that maps the request to actual install/delete/whatever script (which YOU have to write) and the credentials to use - but that's actually the easy part!

Your current script can determine if the files that need to be deleted exist - so use the API to request the "DelFiles". You write a script that deletes the files and verify that it works with admin rights. That script is sent to the system that requested it and it runs with the credentials you specify.. you just need the detect and action scripts, and these can be developed/tested independently.

There's a ZIP in the script vault thread that contains the service, samples, the API function library, and some documentation. I've used this at several clients to deploy apps triggered via my login script over the years. Once set up, you can do all kinds of cool things without ever giving end-users admin rights!

At one client, we actually created a web-based menu of apps that were available for self-service install. I used VBScript to write the request file, but Kix handled the rest. It's built on my tcLib library that interfaces to the Task Scheduler. Be aware that there is a newer version of tcLib that uses SchTasks instead of JT (from the resource kit). I don't recall what version is in the SAIS ZIP file, so you might want to update it if it uses JT.exe. Just replace on tcLib.kxf file with the newer one - they're 100% function compatible.

Give it a go, and post your examples and questions here..

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#210512 - 2015-08-10 05:47 PM Re: If exist file then delete with Wildcards [Re: Glenn Barnas]
hroberts89436 Offline
Fresh Scripter

Registered: 2015-08-04
Posts: 11
Loc: Reno, NV
Glenn,

Thanks for the Info, and I will look into it..... But this is Basic scripting, not advanced. I would like to make something give me the info I need even if I have to do a little extra work (manually delete the file).

Top
#210514 - 2015-08-11 12:16 AM Re: If exist file then delete with Wildcards [Re: hroberts89436]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
The easiest would be to include this in a startup script.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


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

Who's Online
0 registered and 657 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.175 seconds in which 0.125 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