Results 1 to 10 of 10
  1. #1
    xephora's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Posts
    45
    Reputation
    8
    Thanks
    3

    Network Printer Mapping C++/BaT Script

    What's up guys! It's me again, I am going to borrow your brains again! Basically what I am trying to do is create a program or a script that will map a network (remote) Computer to a network printer.

    Pseudo Structure:
    printername = User Input
    hostname = User Input

    I want printer \\printerserver\printer to be mapped to computer \\computername.

    'Assign' + printername + to computer' + hostname.

    You know me I will link the whole source so you can have an idea of what I am trying to do.

    Code:
    #include <iostream>
    #include <windows.h>
    #include <string.h>
    
    using namespace std;
    
    static string hostname;
    static string printername;
    
    int main()
    {
        cout << "This is Auto Mapper \n";
        cout << "Please Provide Target Hostname:";
        cin >> hostname;
        
        cout << "\nPlease Provide Printer Name:";
        cin >> printername;
        cout << "\nApplying Printer now..";
        system("rundll32.exe printerui.dll,printUIEntry /in /c \\" + hostname + "/n \\44vprn01\"" + printername"");
        
        return 0;
    }
    This is causing a compilation error pointing to an argument or how i'm initializing main(). Another thing which I will type out the output for you because I do not understand this..

    expected ')' before string constant
    cannot convert 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >'to 'const char*' for argument '1' to 'int system(const char*)'

    All of this code I did everything from head so I am pretty sure I am doing something wrong here. I did try to search for a function for mapping network printer and was unsuccessful. Any help would be most appreciated!
    Last edited by xephora; 05-04-2011 at 06:37 AM.

  2. #2
    master131's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    Melbourne, Australia
    Posts
    8,858
    Reputation
    3438
    Thanks
    101,669
    My Mood
    Breezy
    Code:
    #include <iostream>
    #include <windows.h>
    #include <string.h>
    
    using namespace std;
    
    static char hostname[50];
    static char printername[50];
    
    int main()
    {
        cout << "This is Auto Mapper \n";
        cout << "Please Provide Target Hostname:";
        cin >> hostname;
        
        cout << "\nPlease Provide Printer Name:";
        cin >> printername;
        cout << "\nApplying Printer now..";
    
        char final[255] = "\0";
        strcat(final, "rundll32.exe printerui.dll,printUIEntry /in /c \\");
        strcat(final, hostname);
        strcat(final, " /n \\44vprn01\"");
        strcat(final, printername);
        strcat(final, "\"");
    
        system(final);
        
        return 0;
    }
    There's probably a better way but I'm tired so w/e. You can't mix string with char* so yeahs (well not just simply like that anyway). Wouldn't coding a batch script be easier.

    Code:
    @EcHo off
    echo This is Auto Mapper
    echo Please Provide Target Hostname:
    set /p hostname=
    
    echo Please Provide Printer Name
    set /p printername=
    
    echo Applying Printer now...
    set "str1=rundll32.exe printerui.dll,printUIEntry /in /c \\"
    set "str2= /n \\44vprn01\"
    set "str3=""
    
    %str1%%hostname%%str2%%printername%%str3%
    pause
    Last edited by master131; 05-04-2011 at 07:29 AM.

  3. #3
    xephora's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Posts
    45
    Reputation
    8
    Thanks
    3
    Problem with this is.. It's like a big giant company i work for and they like to make sure everything is tight net (secured). So they complain if they see anything exposed or easily tweakable. I always create batch files, but i keep them in my usb drive and when I want to apply them to our network I need to convert them into c++ or try the method i'm doing now which is a blend of both.

  4. #4
    Melodia's Avatar
    Join Date
    Dec 2009
    Gender
    female
    Posts
    2,608
    Reputation
    276
    Thanks
    1,662
    My Mood
    Dead
    Quote Originally Posted by xephora View Post
    Problem with this is.. It's like a big giant company i work for and they like to make sure everything is tight net (secured). So they complain if they see anything exposed or easily tweakable. I always create batch files, but i keep them in my usb drive and when I want to apply them to our network I need to convert them into c++ or try the method i'm doing now which is a blend of both.
    "Big Giant Company"
    Use of the System(); Crap Function, Or executing Batch/Random Executable files from USB or everywhere ; No Security Policies at all.

    No matter how many times I read these lines they are as funny.
    Love You All~

  5. #5
    xephora's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Posts
    45
    Reputation
    8
    Thanks
    3
    Well saying The Board of Education which is a big giant company is something I would rather not meantion out loud. lol I get alot of heat when I say that considering everyone hates school. Well.. We manage all the schools so we still are hated by many. Oh and I do agree on "big giant company" sounding funny. Hell that's the only way I describe my company.
    Last edited by xephora; 05-04-2011 at 10:33 AM.

  6. #6
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Code:
    #include <iostream>
    #include <windows.h>
    #include <string.h>
    
    using namespace std;
    
    static string hostname;
    static string printername;
    
    int main()
    {
        cout << "This is Auto Mapper \n";
        cout << "Please Provide Target Hostname:";
        cin >> hostname;
        
        cout << "\nPlease Provide Printer Name:";
        cin >> printername;
        cout << "\nApplying Printer now..";
    
        char sysstr[512] = "";
        sprintf_s(sysstr, 512, "rundll32.exe printerui.dll,printUIEntry /in /c \\%s/n \\44vprn01\"%s\"", hostname.c_str();, printername.c_str());
        system(sysstr);
        
        return 0;
    }
    assuming the end is meant to be like \44vprn01"lolwat"
    Ah we-a blaze the fyah, make it bun dem!

  7. #7
    xephora's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Posts
    45
    Reputation
    8
    Thanks
    3
    Quote Originally Posted by Hell_Demon View Post
    Code:
    #include <iostream>
    #include <windows.h>
    #include <string.h>
    
    using namespace std;
    
    static string hostname;
    static string printername;
    
    int main()
    {
        cout << "This is Auto Mapper \n";
        cout << "Please Provide Target Hostname:";
        cin >> hostname;
        
        cout << "\nPlease Provide Printer Name:";
        cin >> printername;
        cout << "\nApplying Printer now..";
    
        char sysstr[512] = "";
        sprintf_s(sysstr, 512, "rundll32.exe printerui.dll,printUIEntry /in /c \\%s/n \\44vprn01\"%s\"", hostname.c_str();, printername.c_str());
        system(sysstr);
        
        return 0;
    }
    assuming the end is meant to be like \44vprn01"lolwat"
    It wouldn't accept that input. I even tried multiple slashes for network directory i forget that if you need to access \\printerserver\ you will need to type "\\\\printerserver\\", I still get an error though :\

    in function int main()
    invalid operands of types 'const char[48] and 'char[256]' to binary 'operator+'

    Code:
    char hostname[256];
    char printername[256];
    
    int main()
    {
    cout << "This is Auto Mapper \n";
    cout << "Please Provide Target Hostname: \n ->";
    cin >> hostname;
    
    cout << "\nPlease Provide Printe Name: \n ->";
    cin >> printername;
    cout << "\nApplying Printer Now..";
    
    system("RUNDLL32.exe PRINTUI.DLL,PrintUIEntry /in /c \\\\" + hostname + " /n \\\\44vprn01\\" + printername);
    
    return 0;
    }
    This still failed as well, but I cleaned it up for you so it is a bit easier to understand really sorry about the mess.
    Last edited by xephora; 05-04-2011 at 11:35 AM.

  8. #8
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by xephora View Post
    It wouldn't accept that input. I even tried multiple slashes for network directory i forget that if you need to access \\printerserver\ you will need to type "\\\\printerserver\\", I still get an error though :\

    in function int main()
    invalid operands of types 'const char[48] and 'char[256]' to binary 'operator+'

    Code:
    char hostname[256];
    char printername[256];
    
    int main()
    {
    cout << "This is Auto Mapper \n";
    cout << "Please Provide Target Hostname: \n ->";
    cin >> hostname;
    
    cout << "\nPlease Provide Printe Name: \n ->";
    cin >> printername;
    cout << "\nApplying Printer Now..";
    
    system("RUNDLL32.exe PRINTUI.DLL,PrintUIEntry /in /c \\\\" + hostname + " /n \\\\44vprn01\\" + printername);
    
    return 0;
    }
    This still failed as well, but I cleaned it up for you so it is a bit easier to understand really sorry about the mess.

    Your 2nd error was because you can't directly join two char arrays using a + operator, what was the actual error that using strings caused?

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  9. #9
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    Code:
    "rundll32.exe printerui.dll,printUIEntry /in /c \\" + hostname + "/n \\44vprn01\"" + printername""
    Can't add char* (std::string operator) with const char*

  10. #10
    Fovea's Avatar
    Join Date
    Mar 2011
    Gender
    male
    Posts
    325
    Reputation
    101
    Thanks
    411
    My Mood
    Amused
    [highlight=c++]#include <iostream>
    #include <string>

    #include <windows.h>

    int main()
    {
    // You can use a _function_ scope using directive here. Do not pollute the global namespace.

    std::string hostname;
    std::string printername;

    std::string process("rundll32.exe");
    std::string cmdline("PRINTUI.dll,printUIEntry /in /c \\\\)";

    std::cout << "Auto Mapper \n";
    std::cout << "Input target hostname: ";
    std::cin >> hostname;

    std::cout << "\nInput printer name: ";
    std::cin >> printername;

    cmdline += hostname;
    cmdline += " /n \\\\44vprn01\\";
    cmdline += printername;

    CreateProcess(process.c_str(), cmdline.c_str(), NULL, NULL, FALSE, NULL, NULL, NULL);

    return 0;
    }[/highlight]

    Not sure if your command line parameters are correct. That is for you to check.
    Last edited by Fovea; 05-05-2011 at 04:16 PM.