Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Shutdown the computer using an .exe file done in Code Blocks  (Read 3630 times)

0 Members and 1 Guest are viewing this topic.

Lady In Red

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Windows 7
    Shutdown the computer using an .exe file done in Code Blocks
    « on: December 17, 2014, 12:36:56 PM »
    Hello guys.
    I am new on this forum and new also new in learn about batch file.
    Me question is about a code made it in c programming.
    If i run this code allows me to shutdown the computer,but also i want to run this code in a batch file to shutdown the computer.
    The path of this code is : C:\Users\mircea\Desktop\Shutdown My Computer\bin\Debug\Shutdown My Computer.exe.
    I have tried many options but no result.

    Look at this code in C :
    Code: [Select]
    #include <stdio.h>
    #include <stdlib.h>

    int main()
    {
        char ch;
        printf("\n Do you want to shutdown the computer (y/n) ?\n\n");
        printf("  ");
        scanf("%c", &ch);
        if(ch == 'y' || ch == 'Y')
            system("C:\\WINDOWS\\System32\\shutdown -s");
        return 0;
    }

    I wait some advices.
    Thank you.
    All the best.

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: Shutdown the computer using an .exe file done in Code Blocks
    « Reply #1 on: December 17, 2014, 04:55:34 PM »
    No clue why you are using a C program when you can do it all in batch.
    But to run your executable from a batch file just put this in a batch file.
    Code: [Select]
    "C:\Users\mircea\Desktop\Shutdown My Computer\bin\Debug\Shutdown My Computer.exe"

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Shutdown the computer using an .exe file done in Code Blocks
    « Reply #2 on: December 17, 2014, 06:48:19 PM »
    I always wonder why there are so many people who write batch code in C.
    I was trying to dereference Null Pointers before it was cool.

    Blisk



      Intermediate

      Thanked: 1
      • Experience: Familiar
      • OS: Windows 7
      Re: Shutdown the computer using an .exe file done in Code Blocks
      « Reply #3 on: December 19, 2014, 12:35:35 PM »
      why not just
      shutdown /r /f