Jump to content

Hey Joveice,

Long time no seek.

 

Batch files aren't really that advanced, and as far as I know, there's no chance of this working without some form of exe involved.

 

However for a very basic program with buttons, you could use C# to create a Windows Form Applicaion.

If you need any help with that, please PM me on the forums and I can try assist as much as possible.

 

You'd need to create a Windows Form application, add a a few buttons, change the text and maybe the name if you wanted to make it cleaner code, then double click each button and Visual Studio creates the onclick actions.

 

In there you'd need to pop some code to run whatever you wanted:

String command = @"C:\DoStuff.bat";
ProcessInfo = new ProcessStartInfo("cmd.exe", "/c " + command);

 

Regards,

Leon.

Link to post
Share on other sites

11 minutes ago, leonfagan71 said:

Hey Joveice,

Long time no seek.

 

Batch files aren't really that advanced, and as far as I know, there's no chance of this working without some form of exe involved.

 

However for a very basic program with buttons, you could use C# to create a Windows Form Applicaion.

If you need any help with that, please PM me on the forums and I can try assist as much as possible.

 

You'd need to create a Windows Form application, add a a few buttons, change the text and maybe the name if you wanted to make it cleaner code, then double click each button and Visual Studio creates the onclick actions.

 

In there you'd need to pop some code to run whatever you wanted:


String command = @"C:\DoStuff.bat";
ProcessInfo = new ProcessStartInfo("cmd.exe", "/c " + command);

 

Regards,

Leon.

Yea I have never touched the creating of exe files, so I might need alot of help in that case.

Back-end developer, electronics "hacker"

Link to post
Share on other sites

3 minutes ago, Joveice said:

Yea I have never touched the creating of exe files, so I might need alot of help in that case.

visual studio winforms is quite simple when you create a winform project you get the designer and you kist drag and drop where you want the UI elements and as said double click to add a on click action. 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites

2 minutes ago, vorticalbox said:

visual studio winforms is quite simple when you create a winform project you get the designer and you kist drag and drop where you want the UI elements and as said double click to add a on click action. 

So I sould look for how to create winforms?

Back-end developer, electronics "hacker"

Link to post
Share on other sites

4 minutes ago, Joveice said:

So I sould look for how to create winforms?

Yep, I'd start with the most vital bit, 
Visual Studio

https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=Community&rel=15

 

From there, you need to create a new project using the Windows Form Application template.

 

If you don't see it directly, on the left go to Templates->Visual C#->Windows then it will be at the top in the middle section.

 

Regards,

Leon.

Link to post
Share on other sites

22 hours ago, leonfagan71 said:

Yep, I'd start with the most vital bit, 
Visual Studio

https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=Community&rel=15

 

From there, you need to create a new project using the Windows Form Application template.

 

If you don't see it directly, on the left go to Templates->Visual C#->Windows then it will be at the top in the middle section.

 

Regards,

Leon.

Okey, so it wasent hard at all.

 

But how do I force it to run as admin? in both the IDE and after build?

 

Back-end developer, electronics "hacker"

Link to post
Share on other sites

2 minutes ago, Joveice said:

Okey, so it wasent hard at all.

 

But how do I force it to run as admin? in both the IDE and after build?

 

Right click the project name in the right hand side,
Add-> New Item -> Application Manifest File -> Add

Edit the new app.manifest file.
You can then see the Commented out code.
 

Spoiler

<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC Manifest Options
             If you want to change the Windows User Account Control level replace the 
             requestedExecutionLevel node with one of the following.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            Specifying requestedExecutionLevel element will disable file and registry virtualization. 
            Remove this element if your application requires this virtualization for backwards
            compatibility.
        -->
        <requestedExecutionLevel level="asInvoker" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>

  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!-- A list of the Windows versions that this application has been tested on and is
           is designed to work with. Uncomment the appropriate elements and Windows will 
           automatically selected the most compatible environment. -->

      <!-- Windows Vista -->
      <!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->

      <!-- Windows 7 -->
      <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->

      <!-- Windows 8 -->
      <!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->

      <!-- Windows 8.1 -->
      <!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->

      <!-- Windows 10 -->
      <!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->

    </application>
  </compatibility>

  <!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
       DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need 
       to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should 
       also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->
  <!--
  <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
    </windowsSettings>
  </application>
  -->

  <!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
  <!--
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>
  -->

</assembly>

 

In the top section, you can see these three lines:

<requestedExecutionLevel  level="asInvoker" uiAccess="false" />
<requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

 

Your app.manifest can use one of these, I'd assume that you'd use requireAdministrator, in which case you'd need to set uiAccess to true and uncomment that one line.
Be sure that requestedExecutionLevel is not readable anywhere else in the manifest.

 

Regards,

Leon.

Link to post
Share on other sites

2 minutes ago, leonfagan71 said:

Right click the project name in the right hand side,
Add-> New Item -> Application Manifest File -> Add

Edit the new app.manifest file.
You can then see the Commented out code.
 

  Reveal hidden contents


<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC Manifest Options
             If you want to change the Windows User Account Control level replace the 
             requestedExecutionLevel node with one of the following.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            Specifying requestedExecutionLevel element will disable file and registry virtualization. 
            Remove this element if your application requires this virtualization for backwards
            compatibility.
        -->
        <requestedExecutionLevel level="asInvoker" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>

  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!-- A list of the Windows versions that this application has been tested on and is
           is designed to work with. Uncomment the appropriate elements and Windows will 
           automatically selected the most compatible environment. -->

      <!-- Windows Vista -->
      <!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->

      <!-- Windows 7 -->
      <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->

      <!-- Windows 8 -->
      <!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->

      <!-- Windows 8.1 -->
      <!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->

      <!-- Windows 10 -->
      <!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->

    </application>
  </compatibility>

  <!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
       DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need 
       to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should 
       also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->
  <!--
  <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
    </windowsSettings>
  </application>
  -->

  <!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
  <!--
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>
  -->

</assembly>

 

In the top section, you can see these three lines:

<requestedExecutionLevel  level="asInvoker" uiAccess="false" />
<requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

 

Your app.manifest can use one of these, I'd assume that you'd use requireAdministrator, in which case you'd need to set uiAccess to true and uncomment that one line.
Be sure that requestedExecutionLevel is not readable anywhere else in the manifest.

 

Regards,

Leon.

I only got this in the add item.

Text File
HTML Page
JS File
StyleSheet
XML File
XML Schema
XSLT File
BItmmap FIle
Code Analysis......
Icon File
Cursor FIle
Native Resource T.......
Visual C# Class
Visual Basic Class

 

Back-end developer, electronics "hacker"

Link to post
Share on other sites

17 minutes ago, Joveice said:

I only got this in the add item.


Text File
HTML Page
JS File
StyleSheet
XML File
XML Schema
XSLT File
BItmmap FIle
Code Analysis......
Icon File
Cursor FIle
Native Resource T.......
Visual C# Class
Visual Basic Class

 

xksYFcS.png

 

Is this what it looks like? You may have to select Visual C# items on the left.

Link to post
Share on other sites

3 minutes ago, leonfagan71 said:

xksYFcS.png

 

Is this what it looks like? You may have to select Visual C# items on the left.

Oh I clicked on element to high in the tree, now it looks like that!

Back-end developer, electronics "hacker"

Link to post
Share on other sites

3 minutes ago, Joveice said:

Oh I clicked on element to high in the tree, now it looks like that!

<security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC Manifest Options
             If you want to change the Windows User Account Control level replace the 
             requestedExecutionLevel node with one of the following.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            Specifying requestedExecutionLevel element will disable file and registry virtualization. 
            Remove this element if your application requires this virtualization for backwards
            compatibility.
        -->
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="true" />
      </requestedPrivileges>
    </security>

 

 

When running in vs > Error while trying to run project: Unable to start program "Path" The application manifest has the uiAccess attribute set to 'true'.

 

Running build > A reference got returned from the server.

Back-end developer, electronics "hacker"

Link to post
Share on other sites

4 minutes ago, Joveice said:

<security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC Manifest Options
             If you want to change the Windows User Account Control level replace the 
             requestedExecutionLevel node with one of the following.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            Specifying requestedExecutionLevel element will disable file and registry virtualization. 
            Remove this element if your application requires this virtualization for backwards
            compatibility.
        -->
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="true" />
      </requestedPrivileges>
    </security>

 

 

When running in vs > Error while trying to run project: Unable to start program "Path" The application manifest has the uiAccess attribute set to 'true'.

 

Running build > A reference got returned from the server.

Sounds like you have multiple requestedExecutionLevel keys defined.

Link to post
Share on other sites

Okey, now when I click a button all buttons get triggered

 

using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace PortBlocker
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("http://www.freepik.com/free-photos-vectors/logo");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Process process = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = "/C netsh advfirewall firewall set rule name=\"Port Block by DigitalArc\" new enable=yes";
            process.StartInfo = startInfo;
            process.Start();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Process process = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = "/C netsh advfirewall firewall set rule name=\"Port Block by DigitalArc\" new enable=yes";
            process.StartInfo = startInfo;
            process.Start();
            timer1.Enabled = true;
            timer1.Start();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Process process = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = "/C netsh advfirewall firewall set rule name=\"Port Block by DigitalArc\" new enable=no";
            process.StartInfo = startInfo;
            process.Start();
        }

        private void timer1_Tick_1(object sender, EventArgs e)
        {
            Process process = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = "/C netsh advfirewall firewall set rule name=\"Port Block by DigitalArc\" new enable=no";
            process.StartInfo = startInfo;
            process.Start();
        }
    }
}

 

Back-end developer, electronics "hacker"

Link to post
Share on other sites

1 minute ago, Joveice said:

Okey, now when I click a button all buttons get triggered

 


using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace PortBlocker
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("http://www.freepik.com/free-photos-vectors/logo");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Process process = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = "/C netsh advfirewall firewall set rule name=\"Port Block by DigitalArc\" new enable=yes";
            process.StartInfo = startInfo;
            process.Start();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Process process = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = "/C netsh advfirewall firewall set rule name=\"Port Block by DigitalArc\" new enable=yes";
            process.StartInfo = startInfo;
            process.Start();
            timer1.Enabled = true;
            timer1.Start();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Process process = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = "/C netsh advfirewall firewall set rule name=\"Port Block by DigitalArc\" new enable=no";
            process.StartInfo = startInfo;
            process.Start();
        }

        private void timer1_Tick_1(object sender, EventArgs e)
        {
            Process process = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = "/C netsh advfirewall firewall set rule name=\"Port Block by DigitalArc\" new enable=no";
            process.StartInfo = startInfo;
            process.Start();
        }
    }
}

 

The crucial bit is the form code, 
Are you able to zip the entire project and upload it so I can see what's causing the issue?

 

Regards,

Leon.

Link to post
Share on other sites

10 minutes ago, Dat Guy said:

I love how the question was how to write a simple GUI program and the first answer involves the giant .NET framework. Use the Windows API methods for a no-framework solution.

Well I have never used this before and I'm already done with it so I'm gonna say it was simple :)

Back-end developer, electronics "hacker"

Link to post
Share on other sites

11 minutes ago, Dat Guy said:

The programming part might have been simple. The resulting application is a bloated nightmare.

But who am I to judge?

I mean, it looks better than what I was planing to do using some bad box creation with batch

Back-end developer, electronics "hacker"

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×