Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    50
    Thanks
    19
    Thanked 0 Times in 0 Posts

    pass variable to .bat file to create file

    ok
    here is my problem currently i am creating a page to where people can enter a username they want in a text field and it will create a user account for them on my server.
    the text field box is called username
    and a submit button named submit.
    what i need this to do is to on event click of submit button it takes the user name from the text field box and then executes my createusername.bat file using the user name they entered.
    is that possible to be done?

    here is part of my account being created
    the %user%.ini is the file being created but instead of that i want the actual user name they inputted.
    so to sum it up how can i pass a variable from html text box to the batch file
    Code:
    echo Please make all lowercase entries.
    set /p fname= What is your first initial?
    set /p lname= What is your last name?
    echo off
    echo [Account] >> %fname%%lname%.ini
    echo Enabled=1 >> %fname%%lname%.ini
    echo IncomingFXPAllowed=0 >> %fname%%lname%.ini
    echo OutgoingFXPAllowed=0 >> %fname%%lname%.ini
    Last edited by nvysel24; 02-17-2010 at 03:08 PM.

  • #2
    Regular Coder
    Join Date
    Apr 2009
    Posts
    244
    Thanks
    1
    Thanked 20 Times in 20 Posts
    Hey nvysel24,

    I don't know what server-side language/platform you're using (.NET/Classic ASP/PHP/etc...?), but this should apply to all:

    #1. You can read the given .BAT file line by line, find the line you want to replace, and write it.
    #2. To take this further, why use a .BAT file? Can you not just build some command strings and execute them?
    #3. To take this even further, why execute command strings? Whatever language you're using, there should be Active Directory libraries/functionalities available for you to use, which would allow you to do things like create users on a server.

    Regards,
    Mike

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    50
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Mike_O View Post
    Hey nvysel24,

    I don't know what server-side language/platform you're using (.NET/Classic ASP/PHP/etc...?), but this should apply to all:

    #1. You can read the given .BAT file line by line, find the line you want to replace, and write it.
    #2. To take this further, why use a .BAT file? Can you not just build some command strings and execute them?
    #3. To take this even further, why execute command strings? Whatever language you're using, there should be Active Directory libraries/functionalities available for you to use, which would allow you to do things like create users on a server.

    Regards,
    Mike

    well currently i can support asp, asp.net, php and Shtml along with the given html and xhtml.
    I mainly do this as a hobby this isnt for any business or anything and i already created a batch file that creates the user account so all i have to do is type in their name then bam it creates it and registers it to my ftp server.

    I used a batch file because honestly i don't know how to code much. It took me a few hours to just get the batch file working so i was hoping to stick with that/ keep it as simple as possible with maybe a basic html page.

    I found online from different and multiple sources that it can be done I just don't understand what their talkin about really so i came here in search of help

  • #4
    Regular Coder
    Join Date
    Apr 2009
    Posts
    244
    Thanks
    1
    Thanked 20 Times in 20 Posts
    I understand. And I know it can be disappointing to go back and rewrite something that is working and that you spent alot of time on. However, I think in this case you really have to take a deep breath and re-evaluate the way which you're doing it, otherwise in the long run, you will make it much more difficult for yourself.

    Considering doing it your way, since I see no other way but to keep writing to the .BAT file, saving it, then executing it every time someone clicks "Submit", you will now have to spend more time learning how to read/write files. Furthermore, reading and writing to files poses issues that you have to consider. For example, what if two different users click "submit" at approximately the same time causing a deadlock on your file? The point is, doing it your way, you will be digging a big rabbit hole.

    I suggest you do it the ways I mentioned in either #2 or #3. Here's an example google search for doing it like #3, where after clicking on some links, you should be able to find what you're looking for:
    http://www.google.com/search?hl=en&s...&aq=f&aqi=&oq=

    Mike

  • #5
    New Coder
    Join Date
    Mar 2009
    Posts
    50
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Thank you
    well i will take you and not use the batch file but unfortunatley
    my FTP server doesnt use active directory. I run a small server with maybe 50 people so i manually manage most of it and the program i use is Gene6 ftp
    for its accounts it uses ini files for all the settings
    here is an example of one account

    Code:
    [Account]
    CreationDate=2009/09/28 22:52:51
    Enabled=-1
    IncomingFXPAllowed=0
    OutgoingFXPAllowed=0
    Password=MD5:14F4B3AF61F3A0DE4A78EA5C24689F72
    PasswordEnabled=-1
    Address=
    ByPassDomainMaxClients=0
    ByPassDomainMaxConnectionsPerIP=0
    CanChangePassword=-1
    City=
    Company=
    CWDMessageFile=
    DisabledCommands=
    Email=
    ExcludedListOptions=
    ExpirationDate=2009/09/28
    ExpirationEnabled=0
    Fax=
    Group=
    HideHiddenFiles=0
    LogEnabled=-1
    Notes=
    PhoneHome=
    PhoneWork=
    QuotaCheckOnLogin=-1
    QuotaEnabled=0
    RatioEnabled=0
    RealName=
    SecureOnly=-1
    SessionTimeOutEnabled=0
    TimeOfDayAccess0=-1,07:00:00-19:00:00
    TimeOfDayAccess1=-1,07:00:00-19:00:00
    TimeOfDayAccess2=-1,07:00:00-19:00:00
    TimeOfDayAccess3=-1,07:00:00-19:00:00
    TimeOfDayAccess4=-1,07:00:00-19:00:00
    TimeOfDayAccess5=-1,07:00:00-19:00:00
    TimeOfDayAccess6=-1,07:00:00-19:00:00
    TimeOfDayAccessEnabled=0
    TimeOutEnabled=-1
    TransferLimitDownloadEnabled=0
    TransferLimitType=never
    TransferLimitUploadEnabled=0
    WelcomeMessageFile=
    StatsFailedLogins=110
    StatsDownloaded=207380420382
    StatsLastIP=172.17.3.107
    StatsLastLogin=2010/02/05 20:36:10
    StatsLastUsername=acolwell
    StatsLogin=199
    StatsUploaded=52525
    IPAccessList0=172.17.3.107,Allowed,
    StatsFailedDownloads=26
    StatsFilesDownloaded=370
    ParentClass=Movies Only
    TransferLimitLastUpdate=2009/11/06
    this is all stored in the ini file and my batch file had just a template of one which created it and then moved it over.
    is there anyway instead of active directory to have a script in html or php or some server side language create an ini file and place it where it needs to be?
    here is the finished batch file. i know its messy and im sure someone could rewirte it with half as many lines
    or another idea is just edit my batch in a way to where it works with or is a script its self on a webpage
    Code:
    echo Please make all lowercase entries.
    set /p fname= What is your first initial?
    set /p lname= What is your last name?
    echo off
    
    
    echo [Account] >> %fname%%lname%.ini
    echo Enabled=1 >> %fname%%lname%.ini
    echo IncomingFXPAllowed=0 >> %fname%%lname%.ini
    echo OutgoingFXPAllowed=0 >> %fname%%lname%.ini
    echo Password=MD5:81EE28FDDD091211E7745863DB7DD909 >> %fname%%lname%.ini
    echo PasswordEnabled=-1 >> %fname%%lname%.ini
    echo Address= >> %fname%%lname%.ini
    echo ByPassDomainMaxClients=0 >> %fname%%lname%.ini
    echo ByPassDomainMaxConnectionsPerIP=0 >> %fname%%lname%.ini
    echo CanChangePassword=0 >> %fname%%lname%.ini
    echo City= >> %fname%%lname%.ini
    echo Company= >> %fname%%lname%.ini
    echo CWDMessageFile= >> %fname%%lname%.ini
    echo DisabledCommands= >> %fname%%lname%.ini
    echo Email= >> %fname%%lname%.ini
    echo ExcludedListOptions= >> %fname%%lname%.ini
    echo ExpirationDate=2010/02/16 >> %fname%%lname%.ini
    echo ExpirationEnabled=0 >> %fname%%lname%.ini
    echo Fax= >> %fname%%lname%.ini
    echo Group= >> %fname%%lname%.ini
    echo HideHiddenFiles=0 >> %fname%%lname%.ini
    echo LogEnabled=-1 >> %fname%%lname%.ini
    echo Notes= >> %fname%%lname%.ini
    echo PhoneHome= >> %fname%%lname%.ini
    echo PhoneWork= >> %fname%%lname%.ini
    echo QuotaCheckOnLogin=-1 >> %fname%%lname%.ini
    echo QuotaEnabled=0 >> %fname%%lname%.ini
    echo RatioEnabled=0 >> %fname%%lname%.ini
    echo RealName= >> %fname%%lname%.ini
    echo SecureOnly=0 >> %fname%%lname%.ini
    echo SessionTimeOutEnabled=0 >> %fname%%lname%.ini
    echo TimeOfDayAccess0=-1,07:00:00-19:00:00 >> %fname%%lname%.ini
    echo TimeOfDayAccess1=-1,07:00:00-19:00:00 >> %fname%%lname%.ini
    echo TimeOfDayAccess2=-1,07:00:00-19:00:00 >> %fname%%lname%.ini
    echo TimeOfDayAccess3=-1,07:00:00-19:00:00 >> %fname%%lname%.ini
    echo TimeOfDayAccess4=-1,07:00:00-19:00:00 >> %fname%%lname%.ini
    echo TimeOfDayAccess5=-1,07:00:00-19:00:00 >> %fname%%lname%.ini
    echo TimeOfDayAccess6=-1,07:00:00-19:00:00 >> %fname%%lname%.ini
    echo TimeOfDayAccessEnabled=0 >> %fname%%lname%.ini
    echo TimeOutEnabled=-1 >> %fname%%lname%.ini
    echo TransferLimitDownloadEnabled=0 >> %fname%%lname%.ini
    echo TransferLimitType=never >> %fname%%lname%.ini
    echo TransferLimitUploadEnabled=0 >> %fname%%lname%.ini
    echo WelcomeMessageFile= >> %fname%%lname%.ini
    
    
    xcopy "C:\Users\Server\Desktop\Testing Enviro\%fname%%lname%.ini" "C:\Program Files\Gene6 FTP Server\Accounts\Server\users" /C
    Last edited by nvysel24; 02-17-2010 at 07:21 PM.

  • #6
    Regular Coder
    Join Date
    Apr 2009
    Posts
    244
    Thanks
    1
    Thanked 20 Times in 20 Posts
    Okay, in that case, go with step #2 - build and execute command strings. Again, if you Google around, you will find the code you're looking for. I am certain that any language will allow you to do that.

  • #7
    New Coder
    Join Date
    Mar 2009
    Posts
    50
    Thanks
    19
    Thanked 0 Times in 0 Posts
    W%t well you are good
    i chose to use asp/aspx
    and got it working
    with this example i found online and modified it a bit
    Code:
    <%
    thetext="Write this text in the file"
    
    Set fs = CreateObject("Scripting.FileSystemObject")
    
    Set wfile = fs.CreateTextFile("C:\test.ini", True)
    wfile.Write (thetext)
    
    wfile.close
    Set wfile=nothing
    Set fs=nothing
    
    response.write("Text created")
    %>
    there is a couple of problems i see here.
    1 i have to have a test.ini document already there for it to be written else if i dont have it there it errors out. but if i have it there it will fill it in w/ the testing "write this text in the file" this for me will be a problem on down the line because when the create a username i have a template of the ini file of an account and the username is the title of the document so the user of test.ini would be test.
    how would i go about changing that because obviously i can go about making every possible combo of ini file thats already there.

    2 how do i take the variables from the html page of their first initial and last name to the asp script thats on the submit button


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •