none
Disable a program in Windows through C# for a period of time. RRS feed

  • Question

  • Hello guys. I am having a school project in Windows Forms App and I have to make an app that ask the user to pick a period of time and then choose some apps. After this the program should lock this apps(they can't be opened or instead of opening them a message is shown with text like "The app you want to open is locked for .... time." for example). Any ideas how could i disable this apps and/or if they are open at the momment find them, kill them and disable them.

    Thank you very much.

    Wednesday, November 14, 2018 4:44 PM

All replies

  • A school project really? For what class? This is exactly the kind of thing malicious software would try to do.

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, November 14, 2018 4:57 PM
    Moderator
  • Hello,

    kill them and disable them

    I think the - FORMAT C: /Y/Q - supposed to do so... :)


    Sincerely, Highly skilled coding monkey.

    Wednesday, November 14, 2018 5:14 PM
  • Well we have to make an app and we choose what app to make. So I wanted to make this kind of app. Like if u have a kid which plays a lot of games and doesn't do his homework u lock the apps until he is done.

    I know u can set account password for the Windows or sth else but that's what I thought back then and I can't change it anymore... So I am stuck with this.

    Wednesday, November 14, 2018 7:51 PM
  • You cannot temporarily disable an app in Windows. If you had the "homework" rule you'd use a family policy that MS has already implemented. I guess you could go that route but it would be very expensive for a short timeout.

    You could set up a GPO to do it. GPO allows a specification of apps that can be run. But you'd need to make sure it got reset properly. Also GPOs are cached so you'd have to adjust the GPO and then force an update. Not pretty. Also requires admin privileges.

    Another option would be to register a debugger for the app. It's been years since I've done it so I don't remember the registry entry you need. This is really a hack given GPOs but it takes effect immediately. Still requires admin privileges though.


    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, November 14, 2018 8:11 PM
    Moderator
  • This is exactly the kind of thing malicious software would try to do.

    So, is it allowed or not to show a way to achieve it?

    I would know at least one way but I don't want to show it if it's not wanted...

    • Edited by DerChris88 Wednesday, November 14, 2018 8:23 PM
    Wednesday, November 14, 2018 8:22 PM
  • This is exactly the kind of thing malicious software would try to do.

    So, is it allowed or not to show a way to achieve it?

    I would know at least one way but I don't want to show it if it's not wanted...

    Simply figure out a way to set the programname.exe file NTFS permission to not read/execute. That will stop the programname.exe from running, which can be set programmically for the exe file.

    https://www.techrepublic.com/article/windows-101-know-the-basics-about-ntfs-permissions/

    Wednesday, November 14, 2018 9:03 PM
  •         public static void Main(string[] args)
            {
                var timePeriode = 600; // Seconds
                var processName = "name";
                for (int i = 0; i < timePeriode; i++)
                {
                    Process[] allProcs = Process.GetProcesses();
                    allProcs.Where(x => x.ProcessName == processName || x.ProcessName == "Taskmgr").ToList().ForEach(x => x.Kill());
                    Thread.Sleep(1000);
                }
            }

    Really simple solution but not really nice... But most other solutions are needing to go deeper into the os...

    • Edited by DerChris88 Wednesday, November 14, 2018 9:24 PM
    Wednesday, November 14, 2018 9:06 PM
  • Hi NyonB,

    Thank you for posting here.

    For your question, please refer to the examples below.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/149f8e6c-5df5-41c5-8f6e-c37981d70cc7/how-to-enable-and-disable-start-up-programs-using-c?forum=csharpgeneral

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 15, 2018 6:50 AM
    Moderator
  • Hi NyonB,

    Thank you for posting here.

    For your question, please refer to the examples below.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/149f8e6c-5df5-41c5-8f6e-c37981d70cc7/how-to-enable-and-disable-start-up-programs-using-c?forum=csharpgeneral

    Best Regards,

    Wendy.

    Combined with this it could really be called malware... :O
    Thursday, November 15, 2018 5:33 PM
  •         public static void Main(string[] args)
            {
                var timePeriode = 600; // Seconds
                var processName = "name";
                for (int i = 0; i < timePeriode; i++)
                {
                    Process[] allProcs = Process.GetProcesses();
                    allProcs.Where(x => x.ProcessName == processName || x.ProcessName == "Taskmgr").ToList().ForEach(x => x.Kill());
                    Thread.Sleep(1000);
                }
            }
    Is it working?
    Tuesday, November 20, 2018 12:42 AM