C++ Number Tree

email me
#include "stdafx.h"
#include <iostream>

using namespace std;
int main()
{
int n;
cout << "Enter number: "; cin >> n;

for (int i = 1; n>0; n--, i++)
{
for (int j = 1; j<n; j++)
cout << " ";
for (int j = 1; j<i; j++)
cout << "0";
cout << i % 10;
for (int j = 1; j<i; j++)
cout << "0";
cout << "\n";
}
cout << "\npress any key to exit...";
getchar(); getchar();
}


Output

C# – Display Triangle Patterns

email me

using System;

namespace ConsoleApp20
{
class Program
{
static void Main(string[] args)
{
const int ROWS = 5;
const int COLUMNS = 5;

Console.WriteLine(" Left to Right");
for (int i1 = 1, i2 = 1; i1 &lt; COLUMNS * 2; i1++)
{
for (int j = 1; j &lt;= i2; j++)
{
Console.Write(" *");
}

if (i1 &lt; 5)
i2++;
else
i2--;
Console.WriteLine();
}
Console.WriteLine();

Console.WriteLine(" Right to Left");
for (int i1 = 1, i2 = COLUMNS - 1, i3 = 1; i1 &lt; COLUMNS * 2; i1++)
{
for (int j = 1; j &lt;= i2; j++)
Console.Write(" ");

for (int j = 1; j &lt;= i3; j++)
Console.Write(" *");

if (i1 &lt; COLUMNS)
{
i3++;
i2--;
}
else
{
i3--;
i2++;
}
Console.WriteLine();
}
Console.WriteLine();

Console.WriteLine(" Bottom to Top");
for (int i1 = 1; i1 &lt;= ROWS; i1++)
{
for (int j = i1; j &lt; ROWS; j++)
Console.Write("  ");

for (int j = 1; j &lt;= (2 * i1 - 1); j++)
Console.Write(" *");
Console.WriteLine();
}

Console.WriteLine("\n Top to Bottom");
for (int i1 = 1; i1 &lt;= ROWS; i1++)
{
for (int j = 1; j &lt; i1; j++)
Console.Write("  ");

for (int j = 1; j &lt;= (ROWS * 2 - (2 * i1 - 1)); j++)
Console.Write(" *");

Console.WriteLine();
}
Console.WriteLine();
Console.ReadKey();
}
}
}


Output

C# – Simple Desktop Notification With Two Return Codes

email me

This creates a custom notification with two return codes. These return codes can be recorded using desktop management software, such as LANDesk or SCCM. Thus giving you the ability to notify and instantly collect responses from end-users; it provides a method to communicate with an entire fleet of machines.

It works by assigning exit values of 100 and 200 to answer buttons, whatever the user selects becomes the output value, which shows up in the description or return code column of most desktop management software. In SCCM, the value appears in description, in custom queries, and in SSRS reports.

Full Project

Compiled in Visual 2017, and tested under Windows 10.


Output

Yes = 100
No = 200


Form1.cs

using System;
using System.Drawing;
using System.Windows.Forms;

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

Rectangle r = Screen.PrimaryScreen.WorkingArea;
StartPosition = FormStartPosition.Manual;
Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - Width, Screen.PrimaryScreen.WorkingArea.Height - Height);
}

private void Button1_Click(object sender, EventArgs e)
{
Environment.Exit(exitCode: 100);
}

private void Button2_Click(object sender, EventArgs e)
{
Environment.Exit(exitCode: 200);
}
}
}


Form1.Designer.cs

namespace WindowsFormsApp6
{
partial class Form1
{
///

<summary>
/// Required designer variable.
/// </summary>private System.ComponentModel.IContainer components = null;

///

<summary>
/// Clean up any resources being used.
/// </summary>/// <param name="disposing">true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing  (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

///

<summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>private void InitializeComponent()
{
Form1 form1 = this;
form1.button1 = new System.Windows.Forms.Button();
form1.label1 = new System.Windows.Forms.Label();
form1.button2 = new System.Windows.Forms.Button();
form1.pictureBox1 = new System.Windows.Forms.PictureBox();
form1.label2 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)form1.pictureBox1).BeginInit();
form1.SuspendLayout();
//
// button1
//
form1.button1.BackColor = System.Drawing.SystemColors.ButtonFace;
form1.button1.ForeColor = System.Drawing.SystemColors.InfoText;
form1.button1.Location = new System.Drawing.Point(76, 68);
form1.button1.Margin = new System.Windows.Forms.Padding(6);
form1.button1.Name = "button1";
form1.button1.Size = new System.Drawing.Size(88, 39);
form1.button1.TabIndex = 0;
form1.button1.Text = "Yes";
form1.button1.UseVisualStyleBackColor = false;
form1.button1.Click += new System.EventHandler(form1.Button1_Click);
//
// label1
//
form1.label1.AutoSize = true;
form1.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
form1.label1.ForeColor = System.Drawing.SystemColors.ControlText;
form1.label1.Location = new System.Drawing.Point(54, 22);
form1.label1.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
form1.label1.Name = "label1";
form1.label1.Size = new System.Drawing.Size(243, 20);
form1.label1.TabIndex = 2;
form1.label1.Text = "Is your Chrome browser working?";
//
// button2
//
form1.button2.BackColor = System.Drawing.SystemColors.ButtonFace;
form1.button2.ForeColor = System.Drawing.SystemColors.InfoText;
form1.button2.Location = new System.Drawing.Point(184, 68);
form1.button2.Margin = new System.Windows.Forms.Padding(6);
form1.button2.Name = "button2";
form1.button2.Size = new System.Drawing.Size(88, 39);
form1.button2.TabIndex = 6;
form1.button2.Text = "No";
form1.button2.UseVisualStyleBackColor = false;
form1.button2.Click += new System.EventHandler(form1.Button2_Click);
//
// pictureBox1
//
form1.pictureBox1.Image = global::WindowsFormsApp6.Properties.Resources.google;
form1.pictureBox1.Location = new System.Drawing.Point(117, 130);
form1.pictureBox1.Name = "pictureBox1";
form1.pictureBox1.Size = new System.Drawing.Size(108, 101);
form1.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
form1.pictureBox1.TabIndex = 5;
form1.pictureBox1.TabStop = false;
//
// label2
//
form1.label2.AutoSize = true;
form1.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
form1.label2.ForeColor = System.Drawing.SystemColors.ControlText;
form1.label2.Location = new System.Drawing.Point(108, 246);
form1.label2.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
form1.label2.Name = "label2";
form1.label2.Size = new System.Drawing.Size(127, 13);
form1.label2.TabIndex = 7;
form1.label2.Text = "Commlink Industries 2019";
//
// Form1
//
form1.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F);
form1.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
form1.BackColor = System.Drawing.SystemColors.ButtonHighlight;
form1.ClientSize = new System.Drawing.Size(340, 274);
form1.ControlBox = false;
form1.Controls.Add(form1.label2);
form1.Controls.Add(form1.button2);
form1.Controls.Add(form1.pictureBox1);
form1.Controls.Add(form1.button1);
form1.Controls.Add(form1.label1);
form1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
form1.ForeColor = System.Drawing.SystemColors.Window;
form1.Margin = new System.Windows.Forms.Padding(6);
form1.MaximizeBox = false;
form1.MinimizeBox = false;
form1.Name = "Form1";
form1.Opacity = 0.8D;
form1.ShowIcon = false;
form1.ShowInTaskbar = false;
form1.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
form1.Text = "Notification";
form1.TopMost = true;
((System.ComponentModel.ISupportInitialize)form1.pictureBox1).EndInit();
form1.ResumeLayout(false);
form1.PerformLayout();

}

#endregion

private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label2;
}
}


Program.cs

using System;
using System.Windows.Forms;

namespace WindowsFormsApp6
{
static class Program
{
///

<summary>
/// The main entry point for the application.
/// </summary>[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

 

Notes

SCCM WQL Query

select sys.Name, sys.LastLogonUserName, offer.LastExecutionResult, sys.ResourceDomainORWorkgroup from sms_r_system as sys inner join SMS_ClientAdvertisementStatus as offer on sys.ResourceID=offer.ResourceID WHERE AdvertisementID = ‘ABC10589’ and (LastStateName = “Failed”)
SCCM Reporting

 

Launch a website with button

// the button event
private void Button1_Click(object sender, EventArgs e)
{
// launch the webpage
Process.Start("https://google.com");

// the return code, which is recorded in SCCM
Environment.Exit(exitCode: 100);
}

 

Handling a timed, async event

// the button event
private async void Button2_Click_1(object sender, EventArgs e)
{

// minimizes to taskbar
WindowState = FormWindowState.Minimized;

// waits for delay before continuing
await Task.Delay(30000);

// do this after delay
WindowState = FormWindowState.Normal;
}

 

Do not show if specific process is running

public async void CheckProcess()
{
Process[] pname = Process.GetProcessesByName("notepad"); //presentationsettings
if (pname.Length == 0)
WindowState = FormWindowState.Normal;
else
WindowState = FormWindowState.Minimized;
await Task.Delay(10000);      // 10 sec
//await Task.Delay(3600000);  // 1 hour
CheckProcess();
}

 

More Advanced CheckProcess

This will check for specific running apps. If the apps are running, hide notification.

public async void CheckProcess()
{
do
{
bool ScanTitles = false;
bool sTitles = ScanTitles;

Process[] processlist = Process.GetProcesses();
foreach (Process process in processlist)
{
if (!String.IsNullOrEmpty(process.MainWindowTitle))
{
string str = process.MainWindowTitle;
if (str.Contains("Meet")) { sTitles = true; } // Google Hangouts
}
}

ScanTitles = sTitles;
//MessageBox.Show(ScanTitles.ToString());

Process[] pname1 = Process.GetProcessesByName("presentationsettings");  // presentationsettings(presentation mode)
Process[] pname2 = Process.GetProcessesByName("POWERPNT"); // powerpoint
if (pname1.Length == 0  pname2.Length == 0  ScanTitles == false)
{
Show();
}
else
Hide();
await Task.Delay(1000);      // 1 sec

} while (true);

}

 

How I got the Notify Icon to work

Form1.Designer.cs

// notifyIcon1
//
this.notifyIcon1.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info;
this.notifyIcon1.BalloonTipText = "Technology Notification";
this.notifyIcon1.BalloonTipTitle = "Notification";
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "You have a notification!";
this.notifyIcon1.Visible = true;
this.notifyIcon1.Click += new System.EventHandler(this.NotifyIcon1_Click);

Form1.cs

notifyIcon1.Visible = true;

The Event

private void NotifyIcon1_Click(object sender, System.EventArgs e)
{
notifyIcon1.Visible = false;
Show();
WindowState = FormWindowState.Normal;
}

SCCM – Change Client Connection from Intranet to Internet

email me

Use this method—which can easily be scripted—to change the SCCM client connectivity type from Intranet to Always Internet. I found this to be useful when setting up our remote computers to be directed to our DMZ-PKI (a single public-facing server). Once this is set, it doesn’t matter if the users are on site or off site, they are managed by the DMZ endpoint.

Why do this? Due to the complexities of some networks, when remote users travel to an on site facility, [sometimes] their workgroup joined computers will not automatically detect and switch to the local SCCM distribution point, which causes the machines to fall into a non-managed state—this solution prevents that from happening. The computers are always managed through the DMZ. This cuts down on management complexity, DNS connectivity issues associated with remote computers, and guarantees machines remain managed.

 
:: Apply Reg Key
Reg add “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\CCM\Security” /v ClientAlwaysOnInternet /t reg_dword /d 1 /f

:: Restart CM Service
Sc stop CcmExec

Sc start CcmExec


Screenshot

 

Notes

Set Always Internet using ccmsetup

ccmsetup.exe /native SMSSITECODE=ABC CCMALWAYSINF=1 CCMHOSTNAME=HOSTCOMPUTERNAME SMSMP=SCCMMPSERVER SMSSIGNCERT=SITESIGNINGCERT

 

SCCM – Return MP Candidate Information

email me

PowerShell Command

Get-WmiObject -namespace root\ccm\locationservices -class SMS_ActiveMPCandidate


Output

__GENUS : 2
__CLASS : SMS_ActiveMPCandidate
__SUPERCLASS :
__DYNASTY : SMS_ActiveMPCandidate
__RELPATH : SMS_ActiveMPCandidate.MP=”xyz.abc.com”,MPBGRFallbackType=”None”,Type=”Internet”
__PROPERTY_COUNT : 14
__DERIVATION : {}
__SERVER : TEST-COMPUTER
__NAMESPACE : ROOT\ccm\locationservices
__PATH : \\TEST-COMPUTER\ROOT\ccm\locationservices:SMS_ActiveMPCandidate.MP=”xyz.abc.com”,MPBGRFallbackTy
pe=”None”,Type=”Internet”
Capabilities : <Capabilities SchemaVersion=”1.0″><Property Name=”SSL” Version=”1″/><Property Name=”SSLState”
Value=”63″/></Capabilities>
Index : 1
Locality : 0
MasterSiteCode :
MP : xyz.abc.com
MPBGRFallbackType : None
MPFallbackTime : 0
Protocol : OS
Reserved1 :
Reserved2 :
SiteCode :
State :
Type : Internet
Version : 8634
PSComputerName : Test-Computer

 

Or, return just the MP on Internet

(Get-WmiObject -Namespace Root\Ccm\LocationServices -Class SMS_ActiveMPCandidate | Where-Object {$_.Type -eq "Internet"}).MP